On 1 mai 2013, at 14:03, stephane ducasse wrote:

> I was more thinking in something useful :)

Not really useful but fun: simulate classes, subclasses and objects with blocks:

makeCounter := [
        | this value |
        value := 0.
        this := Dictionary new
                at: #set put: [ :newValue | value := newValue ];
                at: #get put: [ value ];
                at: #incr put: [ value := value + 1 ];
                at: #reset put: [ (this at: #set) value: 0 ];
                yourself ].
        
makeDecrCounter := [ 
        | this |
        this := makeCounter value
                at: #decr put: [ (this at: #set) value: (this at: #get) value - 
1 ];
                yourself  ].

aCounter := makeCounter value.
(aCounter at: #incr) value.
(aCounter at: #set) value: 10.
(aCounter at: #reset) value.

aDecrCounter := makeDecrCounter value.
(aDecrCounter at: #decr) value

> 
> 
> On Apr 30, 2013, at 11:07 PM, Marcus Denker <marcus.den...@inria.fr> wrote:
> 
>> 
>> On Apr 30, 2013, at 10:56 PM, Stéphane Ducasse <stephane.duca...@inria.fr> 
>> wrote:
>> 
>>> 
>>> 
>>>     anObject become: String new.
>>> 
>> 
>> 
>> for become: related teaching, this is fun:
>> 
>> magic
>>      #thisIsMagiC  isSymbol ifTrue: [#thisIsMagiC become: #(0)].
>>      #thisIsMagiC at: 1 put: (#thisIsMagiC at: 1) +1.
>>      ^#thisIsMagiC first.
>> 
>> 
> 
> 


Reply via email to