Polymorphism without protocol dilution

David N. Smith dnsmith at watson.ibm.com
Wed Sep 2 14:04:40 UTC 1998


At 20:13 -0400 9/1/98, Bob Arning wrote:
>SNIP...
>>#at:ifAbsentPut:, as implemented elsewhere, evaluates the parameter
>>expression before the message is sent. If it is a block then the block is
>>put into the collection.
>>
>
>Are you referring to actual implementations? I seem to recall from VSE
>work that if the second argument is a block, then it is #value'd if the
>key does not exist and the result is added. Perhaps this was a local
>implementation (I cannot recall at this point) - do different
>implementations exist?
>

I stand corrected. Existing implementations DO seem to value the block, and
oddly enough my  fingers know this since I sometimes write the method. I
always (well, almost always) test things before I append, but since I was
so SURE...


It is true that:

   aDictionary at: key put: [ 1 ]

and:

   aDictionary at: key ifAbsentPut: [ 1 ]

put totally different things into the dictionary. This still feels
inconsistent to me but maybe the 'if' signals the intent to evaluate (as
others have pointed out).

This is an example of lazy evaluation which, if we had it all to do over,
I'd continue to argue against; I'd prefer that it be more explicit.

Sigh...

Dave
_______________________________
David N. Smith
IBM T J Watson Research Center
Hawthorne, NY
_______________________________
Any opinions or recommendations
herein are those of the author
and not of his employer.





More information about the Squeak-dev mailing list