[squeak-dev] Re: [Newbies] Two questions about Smalltalk language design

Chris Muller asqueaker at gmail.com
Sun Dec 30 23:00:53 UTC 2012


>> 2) In Collections, why does "add:" return the object being added, and
>> not "self"?
>>
>> http://stackoverflow.com/questions/14047940/why-does-add-return-the-object-added-in-smalltalk-collections
>
> Smalltalk-72's "vector" had that semantics more or less, when
> assigning a new value to a slot.  Check out "to vector" in
> http://ftp.squeak.org/goodies/Smalltalk-72/ALLDEFS
>
> I can see some reason for that semantics:
>
> One perhaps was that because assignment was just a message send to a
> quoted variable, and you can define its behavior based on the
> receiver.  When the receiver is a quoted vector, your assignment can
> update a slot of it. In many languages (not in Scheme however), the
> value of the assignment is the value to be assigned so you can say:
>
> x := y := 0.
>
> So, it is convenient to make the value of such message to be the value
> to be assigned.
>
> Another is that it certainly is convenient to get back the removed
> element when you are removing an element from a collection.  Making
> add: do the same makes it more symmetric.

Those are my thoughts about that exactly!  Nice to see someone else
appreciate add:/remove: answering the argument besides myself.   :)


More information about the Squeak-dev mailing list