Hi Romano,
It really doesn't work. See this:
f: tail-func [first second] [
print [first second]
either second = 1 [first] [
f 1 - first second - 1
]
]
f 1 400
The set-word skip is in accordance with the way how Help (from RT) is
written, that is all (future compatibility?).
I posted the newest version of http://www.sweb.cz/LMecir/highfun.r to the
web and to my Rebsite. Changes:
Tail-func included (I used a modified inline function idea as Romano
suggested).
Refined corrected (a similar bug as in Apply implementation), moreover
Refined had a "keyword" bug, which is now corrected too (a totally new kind
of trick, probably the most general one), Apply implementation changed a
bit.
Cheers
Ladislav
<<Romano>>
(...)
It works for me. Try the modified version at the end of this message.
(...)
tail-func: function [
{Transparently creates a tail-recursive function.}
[catch]
spec [block!] body [block!]
] [
ic icb i item locals
] [
use [new-locals loop result] [
loop: false
locals: copy []
icb: copy []
i: 1
parse spec [
any [
set item any-word! (
append locals to word! :item
append icb compose [
error? set/any pick new-locals (i) get/any pick locals (i)
]
i: i + 1
) | skip
]
]
set [new-locals body] use locals copy/deep reduce [
reduce [locals body]
]
append icb compose/deep [
either loop [
loop: true
] [
until [
loop: false
error? set/any 'result do (func [] reduce [body])
not loop
]
loop: false
return get/any 'result
]
]
ic: func [
{do body with locals in new context}
[throw]
locals
] icb
throw-on-error [
func spec reduce [:ic locals]
]
]
]
<</Romano>>
--
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the
subject, without the quotes.