Anonymous user
Anonymous recursion: Difference between revisions
→{{header|Smalltalk}}: oops
(→{{header|Smalltalk}}: oops) |
|||
Line 2,785:
Here the closure is defined as "_", and then evaluated (by sending it a <tt>value:</tt> message).
<lang smalltalk>
myMethodComputingFib:arg
|_|
^ (_ := [:n | n <= 1
ifTrue:[
ifFalse:[(_ value:(n
) value:arg.</lang>
b) Define it in a local scope to not infect the outer scopes.
<br>Here, a separate closure is defined (and evaluated with <tt>value</tt>), in which
This is semantically equivalent to the named let solution of Scheme.
<lang smalltalk>
myMethodComputingFib2:arg
^ [
|
[:n | n <= 1
ifTrue:[1]
ifFalse:[(fib value:(n
] value.</lang>
To completely make it anonymous, we could use reflection to get at the current executed block (via thisContext),
|