Writing this
block := [:val |
val >0
ifTrue: [
self logCr: val.
block value: val -1 ]
ifFalse: [ 'foo' ]].
block value: 3
works in a workspace :)
Ben
On Jan 19, 2013, at 8:56 PM, Igor Stasenko wrote:
> On 19 January 2013 03:38, Sean P. DeNigris <[email protected]> wrote:
>> gerard wrote
>>> Hi.
>>>
>>> Excuse me for my poor english.
>>>
>>> I need, for recursive requirements, call a block inside the same block.
>>> That's possible on Smalltalk?
>>>
>
> Integer>>benchFib
>
>>> For example:
>>>
>>> "fibonacci function"
>>> [:fnc :n1 :n2 :limit :numbers | numbers add: n1. (n2 < limit) ifTrue: [
>>> fnc valueWithArguments: {fnc . n2 . (n1 + n2) . limit . numbers}. numbers
>>> ]].
>>>
>>> The objetive is use that block without the :fnc parameter.
>
> [: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 thiscontext.
>
>>>
>>>
>>> Regards
>>
>
>
>
>
>
>
>
> --
> Best regards,
> Igor Stasenko.
>