Hi Ladislav, 

See below....


>
> 1) your implementation uses "keywords": [ref-mode p1 p2 r w comm statement
> ret either get bind to-word append mold on off refinement! word! copy parse
> _*loops _*myspec insert to-path _*mycall if _*loop-detected true return
> until false set do not]. The need to have keywords can be eliminated.
>

I agree. But the idea is to have some kind of stack frame. I found it handy 
to use keywords there. Along the same road a class hierarchy can be 
implemented.


> 2) Why did you use the CATCH function attribute?
>

A local code convention in our project. 

> 3) Refinements can be passed more transparently.
>

I see. But... I use this technique also in Rugby, where this is the only way 
because you are in a distributed environment. Stolen from myself ;-)

> 4) Other simplifications/generalizations were possible. I have "stolen"
> some ideas from my

Cool! I hope others are reading this thread because it is very insightful to 
(have) demonstrate(d) the true power of Rebol: if it isn't there, you can 
built it in no time. Rebol really transforms into what *you* want it to be.
Human-centered software engineering for the programmers....

--Maarten

> CFUNC implementation:
>
> exec: func [body] [do body]
>
> tail-func: function [
>     {Transparently creates a tail-recursive function.}
>     [catch]
>     spec [block!] body [block!]
> ] [
>     ic icb i item
> ] [
>     use [new-locals loop] [
>         loop: 0
>         locals: copy []
>         icb: copy []
>         i: 1
>         parse spec [
>             any [
>                 set-word! | 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 > 0 [
>                 loop: 2
>             ] [
>                 until [
>                     loop: 1
>                     error? set/any 'result exec (reduce [body])
>                     loop = 1
>                 ]
>                 loop: 0
>                 return get/any 'result
>             ]
>         ]
>         ic: func [
>             {do body with locals in new context}
>             [throw]
>             locals
>         ] icb
>         throw-on-error [
>             func spec reduce [:ic locals]
>         ]
>     ]
> ]
>
> fib: tail-func [first second n] [
>     print [first second n]
>     either n = 2 [second] [
>         fib second first + second n - 1
>     ]
> ]
>
>
> Cheers
>     Ladislav
-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to