Category:Smalltalk: Difference between revisions

Line 555:
].
factorial value:10</lang>
(here there is no self, and the code works anywhere outside any class context. A block (aka 'function') is assigned to the "factorial" variable; the <tt>value>:</tt> message sent to the block calledcalls the function. There is no "ˆ" return statement, because the value returned from the block is the value of the last expression in it, and there actually will be no method from which to return).
 
The advantage is that this code can be simply selected as a whole and evaluated. Any variables created will be local to the evaluation scope and not infect the system.
Line 561:
The disadvantage is that it might look somewhat non-Smalltalk-like to not have it in a class/method.
 
However, it shows that Smalltalk albeit being a pure OO-language, does have functional aspects in it, albeit being a pure OO-language.
 
==Citations==
Anonymous user