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" |
On 27 May 2016 at 10:42, Kjell Godo <[hidden email]> wrote: Object>>recurse: aZeroInputValuable"ThatReturnsATwoInputValuable" Yep. Unless my eyes deceive me, that's the Y combinator. You can see a more classically academic implementation at https://rosettacode.org/wiki/Y_combinator#Smalltalk frank |
> On 27-05-2016, at 1:55 PM, Frank Shearar <[hidden email]> wrote: > You can see a more classically academic implementation at https://rosettacode.org/wiki/Y_combinator#Smalltalk Good grief. I didn’t know there are so many ugly languages that I hope never to see again... tim -- tim Rowledge; [hidden email]; http://www.rowledge.org/tim Fractured Idiom:- J'Y SUIS, J'Y PESTES - I can stay for the weekend |
In reply to this post by Kjell 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 |
On 29 May 2016 at 02:04, marcel.taeumel <[hidden email]> wrote: Kjell Godo wrote I bet you'd like it a whole lot less if someone used it and you had to debug it. I've done things that were at most half as tricky as this [1], and it was NOT fun to debug. In fact, trying to do so breaks the debugger if you do the obvious thing and try debug-edit-and-resume, and I still owe a fix for that... frank Best, |
Free forum by Nabble | Edit this page |