[Newbies] Where is the setter for self?

Ralph Johnson johnson at cs.uiuc.edu
Fri Jun 1 17:31:55 UTC 2012

When you print an object, you get its "print string", i.e. a printable
representation of it.

Suppose you define a new class Thingee.   If you select "Thingee new"
and printIt, you will get "a Thingee".  I think you are asking why
some classes behave differently, how they can print something

The way this works is that the system is sending the "printString"
message to the object, and printing the result.  The "printString"
method sends the "printOn:" message.  The "printOn:" method is defined
in class Object to produce the result you see.  However, it is common
for subclasses to override "printOn:" to do something different.  That
seems to be what happened here.

In none of these cases does anybody ever assign to "self".   When you
send a message to an object, that object is "self" for the duration of
the method.  "self" always means "the object that received the message
that caused this method to be invoked".

My first reaction is that it is bad style to override "printOn:" to
produce Javascript.   The main purpose of printOn: is for debugging.
I would think it would be better to make an "asJavascript" method for
producing Javascript.  But I haven't looked at the code so I can't
really say for sure.

-Ralph Johnson

On Fri, Jun 1, 2012 at 12:18 PM, Chris Cunnington
<smalltalktelevision at gmail.com> wrote:
> http://www.osrcon.ca/image2.png
> http://www.osrcon.ca/image1.png
> Yea, I'm not asking this very well. And all things Renggli make my head
> spin.
> In image2, if I inspect the string 'bob' I see self contains a string called
> 'bob'. It does not say "a ByteString", which to me means the usual behaviour
> has been overtaken by something else. We don't get an instance; we get only
> its return value. The instance "a ByteString" was no longer as important as
> its return value.
> In image1, Lukas has overwritten Object>>printString: in
> SUObject>>printString:. And he's using a pattern ("composite with
> decorations" or something) to represent the domain of the JavaScript
> language in Smalltalk.
> If I print "SUSlider new" I don't get "a SUSlider". I get a string of
> JavaScript. What is printed out is what is found in self. If I inspect
> "SUSlider new" I can see in self the string that will be produced. I can
> also see in the decoration instance variable "a SUCreate". With each
> decoration in the chain he makes the string in self gets longer. If I
> execute that entire piece of code from "SUSlider new" down to "onChange:" I
> will get a string of pure JavaScript.
> If how I'm asking this is still really confusing, I'll have to sit on it for
> a few days. I seem to do my best comprehending when I'm asleep.
> Thanks,
> Chris
> On 12-06-01 12:45 PM, Bert Freudenberg wrote:
>> On 01.06.2012, at 17:42, Chris Cunnington wrote:
>> It's a bit hard to make out what you are actually asking.
>> If you implement "printOn:" in any class, then this method determines how
>> instances are printed.
>> "self" always refers to the receiver object of the currently executing
>> message. It cannot be stored into.
>> (LimitedWriteStream on: aString) creates a new stream writing to a string.
>> It inherits "on:" from PositionableStream, which puts aString into the
>> stream's "collection" variable.
>> The "printOn:" method of an object gets a stream passed as its argument.
>> It then sends messages like "nextPut: something" to the stream, which
>> appends something to its collection.
>> What else would you like to know?
>> - Bert -
>> _______________________________________________
>> Beginners mailing list
>> Beginners at lists.squeakfoundation.org
>> http://lists.squeakfoundation.org/mailman/listinfo/beginners
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

More information about the Beginners mailing list