[Newbies] Two questions about Smalltalk language design

Yoshiki Ohshima Yoshiki.Ohshima at acm.org
Thu Dec 27 05:08:17 UTC 2012

There are more knowledgeable people around here, but here is my take:

On Wed, Dec 26, 2012 at 4:32 PM, Sebastian Nozzi <sebnozzi at gmail.com> wrote:
> Hello Smalltalkers,
> I was interacting the other day with an user in a Scala mailing list,
> and he had some questions about Smalltalk. From his FP (functional
> programming) point of view there were some things that looked strange.
> I tried to reply to the best of my ability, but still I don't really
> know the background for these design decisions. So I come to you, real
> experts, hoping for some answers.
> The questions were:
> 1) Why do ST methods return "self" if nothing is explicitly returned?
> (he would have expected something like "Unit" in Scala, or "Void" -
> which I know makes little sense in a world like ST's, so I didn't
> include this in the Stackoverflow question)
> http://stackoverflow.com/questions/14047887/why-do-methods-return-self-by-default-in-smalltalk

>From the language design POV, it's certainly better than simply
returning the value from the last expression in the method.  If it
returns the last value in the expression: the following method would
return the result from #doSomething; but to know what kind of object
would be returned from it, you need to recursively look into many

method1: var1
    var1 doSomething.

Why not return something along the line of nil is.... It certainly is
more useful to be able to chain messages for simple setters.

> 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

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.

-- Yoshiki

More information about the Beginners mailing list