[self-interest] Self Objects
Jecel Assumpcao Jr
jecel at merlintec.com
Tue Nov 29 21:24:28 UTC 2005
sanssecours wrote on Tue, 29 Nov 2005 19:33:02 -0000
> I have to write a little paper about self. I haven't programmed
> anything in Self or Smalltalk yet and only have a little experience in
> the mainstream programming languages out there (C,Java..). I think I
> already understand the "basics" of the Language. However there are
> some code samples on the Self-Homepage that I don't understand for
Could you give a little more information about where you found this
example? There are a few things that are a bit strange about it.
> (| x. y |
> x: 3.··y: 4.
> x squared + y squared)
> Ok as far as I know that sample shows an object with two slots that
> contain the objects x and y but what do the rest of the code mean. It
> seems like the code declares some method that returns x squared + y
> squared but whats the name of this method how can you use this method
> (in Java something like: Object.Method() - whats the corresponding
> code in Self). And what do the Points: "··" between x: 3 and y: 4
> mean. It woul be very nice if sombeody out ther could help me.
I should point out that the textual syntax became less important when
the graphical programming environment was introduced in Self 4.0 (1995)
though it is still very convenient for discussing code via email and
stuff like that.
Your guess is correct - the syntax for an object or method is
( | slots | code )
where the "code" part is empty for regular objects (not the case above)
so they simply return themselves when accessed as a value in some slot.
Methods can have local slots like "x" and "y" in the example but they
also can have argument slots that don't make sense for regular objects.
On the other hand, having a method loose like that instead of defined in
some slot doesn't make any sense, as you also guessed.
The two dashes before the "y:" could be a valid binary selector so the
code could be interpreted as
set "x" to 3
send "--" to self with the result of setting "y" to 4 as its argument
return the sum of the squares of "x" and "y"
The second line seems *very* strange. If I had to guess I would say that
some text transformation(s) converted two tabs or similar formatting
whitespace into dashes.
More information about the Self-interest