Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion How to change a class' behavior from outside?

Received: by 10.42.146.3 with SMTP id h3mr15298768icv.2.1321209533077;
        Sun, 13 Nov 2011 10:38:53 -0800 (PST)
X-BeenThere: newspeaklanguage@googlegroups.com
Received: by 10.231.123.88 with SMTP id o24ls8630485ibr.3.gmail; Sun, 13 Nov
 2011 10:38:52 -0800 (PST)
MIME-Version: 1.0
Received: by 10.50.6.200 with SMTP id d8mr2154395iga.0.1321209532763; Sun, 13
 Nov 2011 10:38:52 -0800 (PST)
Received: by t36g2000prt.googlegroups.com with HTTP; Sun, 13 Nov 2011 10:38:47
 -0800 (PST)
Date: Sun, 13 Nov 2011 10:38:47 -0800 (PST)
In-Reply-To: <90f35a3b-0f60-41a0-a632-975d8503df5d@n6g2000vbg.googlegroups.com>
References: <c1d6b0da-42c5-4f32-8736-fff335bbf07b@x8g2000yql.googlegroups.com>
 <CAPSzXpzwxok2sMzuYWCA9TziV7xyQi7sfWCmCSeGmXc9i0-Cyg@mail.gmail.com> <90f35a3b-0f60-41a0-a632-975d8503df5d@n6g2000vbg.googlegroups.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8)
 AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.120 Safari/535.2,gzip(gfe)
Message-ID: <fb48480c-d361-48e6-bd15-c3a11e689593@t36g2000prt.googlegroups.com>
Subject: Re: How to change a class' behavior from outside?
From: Gilad Bracha <gbra...@gmail.com>
To: Newspeak Programming Language <newspeaklanguage@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi Damien,

Tjis is known as class-hierarchy inheritance - the ability to inherit
and extend entire class hierarchies. It works, and hass been working
for a long time, with the caveat that you have to give a name to the
superclass (which will be fixed eventually). We use this in the parser
combinator library for example (BlocklessCombinatorialParsing is
designe dto be mixed in with CombinatorialParsing and override its
behavior).

Real world examples of this are not all that common. Eliot recently
had a case where he wanted to override the Debugging module so it
would better support debugging a DSL.
I am interested to know what your actual intended scenario was>

On Nov 11, 6:26=A0am, Damien Cassou <damien.cas...@gmail.com> wrote:
> Thank you very much. For the record, here is what I wanted to do by
> "changing a class' behavior from outside". The class C defines a
> module with some features and I can't change its source code. In my
> module D, I want to change the behavior of some parts of C. I then
> create a subclass of C and I create subclasses of some of its inner
> classes (the new classes must have the name of their super class).
>
> class C =3D (||) (
> =A0 class C1 =3D (||) (
> =A0 =A0 =A0 =A0 f =3D ( ^ 1)
> =A0 ) : ()
> =A0 class C2 =3D (||) (
> =A0 =A0 =A0 =A0 g =3D ( ^ C1 new f)
> =A0 ) : ()
> ) : ()
>
> class D withC: CClass =3D (| realC =3D CClass. |) (
> =A0 class ExtendedC =3D realC (|SuperC1 =3D super C1.|) (
> =A0 =A0 class C1 =3D SuperC1 (||) (
> =A0 =A0 =A0 =A0 =A0 f =3D ( ^ 2)
> =A0 =A0 ) : ()
> =A0 ) : ()
> ) : ()
>
> Now, if I execute :
>
> (D withC: C) new ExtendedC new C2 new g
>
> I get 2 instead of 1. Which really means I can have a private version
> of some classes I don't own.
>