logo       

Re: block in recursion, Any cure for that kind of situation?: msg#00111

lang.smalltalk.squeak.beginners

Subject: Re: block in recursion, Any cure for that kind of situation?

Hi Hilaire,

on Wed, 23 Jan 2008 09:49:07 +0100, you wrote:


Le mardi 22 janvier 2008 à 22:16 +0000, Marcin Tustin a écrit :
I'm an idiot. That doesn't work either. Why not?

Because still nested, I guess.
Anyway I want to use that for teacher to design programmaticaly
interactige geometry figure for Drgeo. So it have to keep simple and be
usable in a Workspace.

The only alternative I see is to define a class with methods, but it is
a bit more complex for the target audiance.

You don't have to. I use recursive blocks in Smalltalk workspace all the time. The "trick" is from the Self language, which always clones activation record before using them. Example:

recursiveBlock := [:argV |
argV < 1
ifFalse: [argV + (recursiveBlock clone value: argV - 1)]
ifTrue: [argV]].

recursiveBlock clone value: 17

You could send #copy instead of #clone but I prefer the latter in honor of Self.

Enjoy!

/Klaus

P.S. beware of the #fixTemps symptom in Squeak's implementation of blocks, was discussed several times over in squeak-dev.

Hilaire



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise