Prevent cloning of clones

Brian Rice water at tunes.org
Mon Apr 25 13:43:49 PDT 2005


On Apr 25, 2005, at 1:10 PM, Adde wrote:

> Brian Rice wrote:
>
>> First, try looking at src/lib/dimensioned.slate which has a full 
>> units library. Also, use Oddball clone, which has this behavior that 
>> you cannot clone it again. Then, have it delegate 
>> (addImmutableDelegate:valued: or set what delegation slot it does 
>> have) to the intended parent. Normally, we don't bother with that 
>> level of control yet, though.
>>
>> On Apr 25, 2005, at 5:56 AM, Adde wrote:
>>
>>> I'm trying to create a representations for different units of 
>>> measurement in SVG and the best i could come up with was the 
>>> following:
>>>
>>> SVG addPrototype: #Unit derivedFrom: {Cloneable}.
>>> SVG Unit addSlot: #postfix.
>>> SVG Unit traits addSlot: #Pixels valued: (SVG Unit clone `>> 
>>> [postfix: 'px'.]).
>>> u@(SVG Unit traits) toXML [ u postfix ].
>>>
>>> However, there is no point in doing 'SVG Unit Pixels clone' so I was 
>>> wondering how I can make it behave like numbers, ie. '1 clone' gives 
>>> an error message.
>>>
>>> /Adde
> Ok, this is what i've got so far:
>
> SVG addPrototype: #Unit derivedFrom: {Cloneable}.
> SVG Unit addSlot: #postfix.
> SVG Unit addSlot: #Pixels valued: Oddball clone `>> 
> [addImmutableDelegate: #super valued: SVG Unit clone `>> [postfix: 
> 'px'.].].
>
> u@(SVG Unit traits) toXML [ u postfix ].
>
> I can still clone SVG Unit Pixels, though. I guess what it does is 
> that it clones SVG Unit by delegating the clone call.
> Feels like i'm running in circles here ;)

The problem is that you are messing with multiple inheritance - when 
you call addImmutableDelegate:valued:, it becomes the /first/ parent 
consulted during lookup. What you have to do is run this:

SVG Unit Pixels addImmutableDelegate: #super before: #traits1 valued: 
Oddball traits.

I strongly suggest that you just forget about this issue and don't 
worry about the safety factor for now. Focus on the real design issues 
first; your code is a mess and is not re-using the very useful library 
I mentioned above. Try this instead:

load: 'src/lib/dimensioned.slate'.
SVG addImmutableSlot: #Pixel valued: (BaseUnit name: 'pixel' abbrev: 
'px').

Doesn't that look better? It also can be used for actual algebraic 
operations, e.g.:

Slate> BaseUnit name: 'pixel' abbrev: 'px'.
px
Slate> 4 with: pixel.
4_px
Slate> it * 5.
20_px
Slate> it / (1 with: in).
20_px/in

The underscores are not really suitable for output into XML, but you 
can easily do something different there, or we could fix the print-out 
or provide some other means. In any case, you have multi-dispatch and 
can handle the case specifically in any output method.

--
Brian T. Rice
LOGOS Research and Development
http://tunes.org/~water/




More information about the Slate mailing list