Anonymous user
Category:Smalltalk: Difference between revisions
m
→Message Sends
m (→Message Sends) |
|||
Line 390:
===Message Sends===
<lang smalltalk>
a factorial even "send the 'factorial' message to whatever
then send 'even' to whatever that returned"
a + 1 "send a '+' message, passing the argument '1' to whatever 'a' refers to"
(a + 1) squared "send '+' to 'a', then send 'squared' to whatever we get from it"
a , b "send the (binary) ',' message,
which performs collection-concatenation (arrays, strings, etc)"
arr at:1 put:'foo' "send the 'at:put:' message to 'arr',
passing two arguments, the integer '1' and a string"
a > b ifTrue: [ a print ] "send the 'ifTrue:' message to whatever 'a > b' returned (a boolean, usually),
passing a block closure as argument.
The implementation of boolean will either evaluate
or not evaluate the passed block's code"
a > b ifTrue: [ a ] ifFalse: [b] "send 'ifTrue:ifFalse:' to the object returned by 'a > b',
passing two block closures as arguments.
The 'ifTrue:ifFalse:' method will evaluate one of them
and return that block's return value as its own return value"
b := [ ... somCode... ]. "assign a block to the variable 'b'"
...
b value "evaluate the block's code (call the lambda closure)"
b2 value:123 "evaluate another block
=== Other ===
|