[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Sep 19 10:31:55 1994 
Subject:Re: flavour-question 
From:Tom Khabaza 
Volume-ID:940919.01 

Jonathan is right (of course, since he agrees with me!).

To continue the colour analogy a bit further:

There is a "default colour" (that is, a default metaflavour, namely
flavour_flavour).  New blobs (flavours) will always have this as their
colour unless explicitly overridden at create time.  The problem is that
there is no obvious way of making the default colour inside a blob be
the colour of that blob.

By the way, I was a bit slow when I made my original reply, and I missed
out an important point (well, it's been a busy year):

You can of course make the "setmember" behaviour the default for all
flavours, by modifying flavour_flavour:

    flavour flavour;
        ivars set=[];
        defmethod after new(x) -> x; x :: set -> set; enddefmethod;
    endflavour;

and then, without having to set any metaflavours at all, we get:

    flavour person;
        ivars name;
        defmethod printself;
            pr("<"); pr("person"); pr(space); pr(name); pr(">");
        enddefmethod;
    endflavour;

    vars    p = make_instance([person name fred]),
            q = make_instance([person name sue]);

    person_flavour <- set =>
    ** [<person sue> <person fred>]

and of course:

    flavour city_person isa person; endflavour;                 

    vars    x = make_instance([city_person name jane]),                 
            y = make_instance([city_person name jack]);

    city_person_flavour <- set =>
    ** [<person jack> <person jane>]

But note that this is probably not quite what we want, because
person_flavour doesn't know about city people, so:

    person_flavour <- set =>
    ** [<person sue> <person fred>]

That is, the setmember functionality applies to each flavour
individually, not taking account of the inheritance hierarchy.  To make
it do so we can do:

    flavour flavour;                 
        ivars set=[];                 
        defmethod after new(x) -> x; ^ add_instance(x, self); enddefmethod;                 

        defmethod add_instance(x, flav);                 
            lvars flav c;
            if member("set", flav<-myflavour<-instance_variables) then                 
                x :: (flav <- set) -> flav<-set;                 
                for c in flav<-components do ^ add_instance(x, c); endfor;                 
            endif;                 
        enddefmethod;                 
    endflavour;

(Note that you should restart Poplog to try this, as otherwise it will
tend to interact with the previous definition.  We cannot use the normal
cancelling technique on flavour_flavour and expect things to work!)

So we then get the inheritance behaviour we would probably want:

    flavour person;
        ivars name;
        defmethod printself;
            pr("<"); pr("person"); pr(space); pr(name); pr(">");
        enddefmethod;
    endflavour;

    vars    p = make_instance([person name fred]),
            q = make_instance([person name sue]);

    person_flavour <- set =>                 
    ** [<person sue> <person fred>]                 

    flavour city_person isa person; endflavour;                 

    vars    x = make_instance([city_person name jane]),                 
            y = make_instance([city_person name jack]);                 

    city_person_flavour <- set =>                 
    ** [<person jack> <person jane>]                 

    person_flavour <- set =>
    ** [<person jack> <person jane> <person sue> <person fred>]

BUT NOTE:
We have set the system to keep track of all instances of all flavours.
This could be expensive in space, because objects will not be garbage
collected except when all the flavours they inherit from are destroyed
(i.e. usually never).  This could be fixed by using a "tmpboth" property
instead of a list, and converting it to a list at a convenient point.
Or we might want more fine-grained control over garbage collection,
making some flavours garbage-collected by default and some only when an
instance is explicitly deleted.

Note that we are still not really making the setmember behavour
inheritable, but simply applying it to all flavours.  To make it
inheritable is a problem yet to be solved (though as I hinted in my
previous message I would be willing to try).
tom