[squeak-dev] Re: The Object>>recurse: Method

marcel.taeumel Marcel.Taeumel at hpi.de
Sun May 29 09:04:58 UTC 2016


Kjell Godo wrote
> Object>>recurse: aZeroInputValuable"ThatReturnsATwoInputValuable"
> 
> ^( aZeroInputValuable value
>  ) value:( self )value:[ :anObject | anObject recurse: aZeroInputValuable
> ]
> 
> "Object>>recurse:
> 
> does for recursion what >>do: does for iteration
> 
> it enables any Object O to do recursion
> Without writing a new recursive method in the Class of O
> 
> It does this even if the
> BlockClosures in this version of Smalltalk being used
> Can only do tail recursion accurately
> Like in Dolphin Smalltalk 6
> 
> You call it like
> 
> ( anObject recurse:[[ :anobject :recurse |
>        ( anobject someChildren collect:[ :child |
>               ( something something ).
>               ( ( recurse value:( child something ) ) something )
>               ]
>        ) asSomeObjectSomething
> ]] )
> 
> ok
> So i haven't actually tried it yet
> so i do not actually know if it actually works
> so it's too hot off the presses for that
> because I'm more into a math major than physics
> i guess i always like math way better
> and so i have a tendency to say      that has already been shown
> but i can't see how it can fail
> So i am putting it out there right now without testing it first
> each recursion creates a new twoInputValuable
> and the >>recurse: method keeps getting called
> from inside of itself
> 
> so i think it works
> 
> but i guess you have to try it to find out
> 
> if you can figure an easier way
> or why it can't work
> then please show it
> 
> i have been trying to do this for a long time
> and it shocks me that it's so small     must be something wrong in there
> so if you easily find a better way
> or that it's no way at all
> then i missed it and I'm too early
> and I'm semi mal informed
> ie stupeid
> and I'm a baaad scientrist       cepting I'm not one
> et all
> not quite easily done
> 
> Kjell E Godo"

Hi Kjell,

I suppose that this code is a suggestion for Trunk? If you did not try it
out, where does it come from? Dolphin Smalltalk 6?

It does look like a valuable addition to me. Although, I read it like
re-curse and thought of Monkey Island and LeChuck. :-D Are there other words
for this?

#combine:
#doRecursive:

Anyway, it seems to work for Fibonacci:

6 recurse: [[:number :step | 
   number caseOf: {
      [0] -> [1].
      [1] -> [1].
   } otherwise: [
      (step value: number - 2)
         + (step value: number - 1)]]].

Best,
Marcel



--
View this message in context: http://forum.world.st/The-Object-recurse-Method-tp4897901p4897988.html
Sent from the Squeak - Dev mailing list archive at Nabble.com.


More information about the Squeak-dev mailing list