[Prev][Next][Index][Thread]

Re: Dylan Features



In article <8mmuun$e8n$1@nnrp1.deja.com>, oodl@my-deja.com wrote:

> In his original post, Brian Campbell said that "when Dylan
> had Scheme-style syntax, that you could add slots to individual
> instances."
> 
> Can someone describe the functionality that Brian mentions?  The
> scheme-style syntax was before my time.

>From the original Dylan book:


-------------------------------------------------------------
P94:

[Generic Function]
add-slot   slot-owner #key type allocation setter getter
           debug-name init-value init-function init-keyword
=> slot-descriptor

add-slot adds a slot to slot-owner (which should be a class or 
singleton) and returns a slot descriptor for it.  The instances of 
slot-owner are updated to contain the new slot.  This function is called 
by define-class and define-slot.

[...]

If the slot-owner is a singleton, then allocation must be instance, 
constant, or virtual, and init-keyword cannot be specified.


P96:

Singletons

Singletons provide a way to add slots and methods to single instances.  
This let [sic] programs specialize a single object, without changing 
other objects of the same class, and without defining a whole new class 
just for the object.

Singletons and classes are currently the only types of specializers 
available in Dylan.

A singleton is little more than a pointer to a single object.  The 
singleton's sole purpose is to indicate that object, so that a method 
can be created that specializes on the object. [...]
-------------------------------------------------------------


> To me, being able to specialize a method on a singleton provides
> that functionality.  What am I missing?

Well, I think you're exactly right.  When used dynamically, add-slot was 
really only a shortcut for adding methods to the getter and setter 
Generic Functions.  When define-class (and define-slot) were changed 
into declarations rather than functions the need for add-slot in that 
case went away and since it is redundant in the dynamic case it went 
away completely.

That's my guess :-)

-- Bruce



References: