Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!gatech!swrinde!pipex!bnr.co.uk!bcarh8ac.bnr.ca!bcarh189.bnr.ca!nott!cunews!dbuck
From: dbuck@superior.carleton.ca (Dave Buck)
Subject: Re: Syntax Question...
X-Nntp-Posting-Host: superior.carleton.ca
Message-ID: <D7q76L.Jo4@cunews.carleton.ca>
Sender: news@cunews.carleton.ca (News Administrator)
Organization: Carleton University, Ottawa, Canada
References: <1995Apr28.004913.28986@mercury.ncat.edu>
Date: Fri, 28 Apr 1995 03:32:44 GMT
Lines: 50

In article <1995Apr28.004913.28986@mercury.ncat.edu>,
 <dowtin@mercury.ncat.edu> wrote:
>-Language: IBM Smalltalk v2
>
>I'm a relative newbie, and would like to know a little more about the
>following syntactical blunder:
>
>
>| temp |
>
>temp := Dictionary new;
>  at: 'key' put: 'element'.

The semicolon (;) means "send the next message to the same receiver as
the last message".  You could paraphrase it as "then".  It allows you
to send a number of messages to the same object.  In your example, the
';' after the new message causes the return value of the 'new' message
to be discarded (i.e., ignore the new instance) and send the next
message (at:put:) to the same receiver as the last message.  The last
message was 'new'.  The receiver was the Dictionary class.  The
'at:put:' message, therefore, is sent to the Dictionary class (which is
wrong).

For a more confusing example, try this one:

Array new: 5 squared ;
    at: 2 put: $h

This doesn't work.  The question, though, is "what object receives the
at:put: message?"  The answer is the Array class.  The evaluation goes
like this:

5 squared  --> 25
Array new: 25  --> anArray

The last message was new: and its receiver was the Array class.  The
next message is sent to the same receiver as the last message.

Array at: 2 put: $h

Does it make sense now?

David Buck
dbuck@ccs.carleton.ca

_________________________________
| David K. Buck                 |
| dbuck@ccs.carleton.ca         |
| The Object People             |
|_______________________________|
