Talk:Anonymous recursion: Difference between revisions

Content added Content deleted
(Trying to squeeze my comments into this overly long talk page.)
Line 184: Line 184:
:Agreed. I think this strikes home. You could stuff that 'recur' function into some library, and use it whenever needed, right? --[[User:Abu|Abu]] 07:46, 9 January 2011 (UTC)
:Agreed. I think this strikes home. You could stuff that 'recur' function into some library, and use it whenever needed, right? --[[User:Abu|Abu]] 07:46, 9 January 2011 (UTC)
:: Is there something I'm doing wrong? The above version of 'fib' just returns its argument. --[[User:Abu|Abu]] 09:15, 12 January 2011 (UTC)
:: Is there something I'm doing wrong? The above version of 'fib' just returns its argument. --[[User:Abu|Abu]] 09:15, 12 January 2011 (UTC)
::: You probably used Ruby 1.8, while I used Ruby 1.9. They changed the rules for when a block parameter has the same name as a variable outside the block. I misunderstood the rules for Ruby 1.8, and wrote a recursive singleton method, when a recursive block would have worked. --[[User:Kernigh|Kernigh]] 04:04, 11 February 2011 (UTC)


:Concerning "recursion implies a function", it depends on what you consider a function. The GOSOB in the Basic code snippet is not really a function call. That's why I used the term "call" instead of "function". A Forth solution would involve two or three new immediate control words, similar to BEGIN/WHILE/REPEAT. In the PicoLisp version (and also in your second Ruby version, if I understand it right), the first pass through the 'recur' body does not actually involve a function call, but it is executed in the context of the surrounding function. --[[User:Abu|Abu]] 07:57, 9 January 2011 (UTC)
:Concerning "recursion implies a function", it depends on what you consider a function. The GOSOB in the Basic code snippet is not really a function call. That's why I used the term "call" instead of "function". A Forth solution would involve two or three new immediate control words, similar to BEGIN/WHILE/REPEAT. In the PicoLisp version (and also in your second Ruby version, if I understand it right), the first pass through the 'recur' body does not actually involve a function call, but it is executed in the context of the surrounding function. --[[User:Abu|Abu]] 07:57, 9 January 2011 (UTC)

----

* "GOSUB" looks like a function call to me, because it reminds to me of those assembly instructions (6502 'jsr', 65816 'jsl' or PowerPC 'bl') that provide the usual way to call functions in assembly language.
* I could stuff Ruby 'recur' into a library. The above version was not good, because a Ruby program can have multiple call stacks (from fibers or threads). I post a different version of Ruby 'recur' on the page, where 'recurse' has no $ sign.
* Ruby is different from PicoLisp here: the first pass through the 'recur' block really is a function call! For example, <tt>recur { recurse }</tt> would be an infinite loop (until I run out of memory, with a very long stack trace), but <tt>recur { next 5; recurse }</tt> would return 5, because 'next' is the Ruby keyword to return from a block.
* I cannot find the difference between an ''invisible function'' and a ''function-that-is-not-considered-a-function''. If the wrong solutions use the invisible functions, and the correct solutions use the functions that are not considered functions, then I cannot know whether each solution is correct or wrong! --[[User:Kernigh|Kernigh]] 04:04, 11 February 2011 (UTC)


=== completion of the task ===
=== completion of the task ===