Jan. 20, 2013
8:34 a.m.
On 19 Jan 2013, at 20:56, Igor Stasenko <siguctua@gmail.com> wrote:
[:param | param >0 ifTrue: [ thisContext closure value: param - 1 ]
] value: 5
but this will be much slower than just use recursion with methods because of this context.
This is so cool, Igor. I didn't know about this trick. All in all, writing factorial like this is pretty elegant: [ :n | n < 2 ifTrue: [ 1 ] ifFalse: [ n * (thisContext closure value: n - 1) ] ] value: 5 AFAIK, this is impossible in Lisp like languages. Thanks for teaching us ! Sven -- Sven Van Caekenberghe http://stfx.eu Smalltalk is the Red Pill