Category:Smalltalk: Difference between revisions

Content added Content deleted
Line 413: Line 413:


=== Other ===
=== Other ===
<lang smalltalk>expr1 . expr2 "statements within a method or block are separated by a fullstop."
<lang smalltalk>expr1 . expr2 "statements within a method or block are separated by a fullstop."


foo := bar "assignment; let foo refer to the object to which bar refers to (at that particular point in time)"
foo := bar "assignment; let foo refer to the object to which bar refers to
(at that particular point in time)"


^ a + 1 "return; the value of the 'a+1' message send is returned as the value of the current method invocation."
^ a + 1 "return; the value of 'a+1' as the value of the current method invocation."


'hello' print. 'world' print "statements are separated by a period; just like in english"
'hello' print. 'world' print "statements are separated by a period; just like in english"


|a b c| "local variables; introduces 'a', 'b' and 'c' in the current scope (let-like local bindings)"
|a b c| "local variables; introduces 'a', 'b' and 'c' in the current scope
(let-like local bindings)"


r msg1; msg2 "so called cascade; first send msg1 to r, ignoring the return value, then send msg2.
r msg1; msg2 "so called cascade;
The value of the expression is result from last message.
first send msg1 to r, ignoring the return value,
Syntactic sugar for (t := r) msg1. t msg2
then send msg2.
but an expression, not a statement (and with an anonymous variable 't')"</lang>
The value of the expression is result from last message.
Syntactic sugar for (t := r) msg1. t msg2
but an expression, not a statement (with an anonymous variable 't')"</lang>


=== Class Definition ===
=== Class Definition ===