Hi Ladislav,

Don't you copy the body?

>> x: tail-func [a][either a <= 0 [20] [x a - 1]]
>> x2: tail-func [a][either a <= 0 [200] [x a - 1]]
>> x 3
== 20
>> x2 3
== 20
---
Ciao
Romano

----- Original Message ----- 
From: "Ladislav Mecir" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, November 22, 2001 4:39 PM
Subject: [REBOL] Re: tail-func: for the gurus


> Hi all,
> 
> I changed the implementation of Tail-func to support the THROW attribute:
> 
> tail-func: function [
>     {Creates a tail-recursive function.}
>     [catch]
>     spec [block!] body [block!]
> ] [
>     ic icb i item locals result does-body
> ] [
>     use [new-locals stop] [
>         stop: 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]
>         ]
>         use [finish] [
>             does-body: has [ret] compose [
>                 finish: [return get/any 'result]
>                 set/any 'ret do (reduce [body])
>                 finish: [get/any 'result]
>                 get/any 'ret
>             ]
>             append icb compose/deep [
>                 either stop [
>                     stop: false
>                 ] [
>                     until [
>                         stop: true
>                         error? set/any 'result (:does-body)
>                         stop
>                     ]
>                     stop: false
>                     do finish
>                 ]
>             ]
>         ]
>         ic: func [
>             {do body with locals in new context}
>             [throw]
>             locals
>         ] icb
>         throw-on-error [
>             func spec reduce [:ic locals]
>         ]
>     ]
> ]
> 
> 
> -- 
> To unsubscribe from this list, please send an email to
> [EMAIL PROTECTED] with "unsubscribe" in the 
> subject, without the quotes.
> 

-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to