gforth
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gforth] naive fibonacci


From: Terrence Brannon
Subject: Re: [gforth] naive fibonacci
Date: Sun, 7 Mar 2010 05:36:12 -0500

On Sat, Mar 6, 2010 at 9:59 PM, Elko Tchernev <address@hidden> wrote:

>
> This way, the parameter will be dropped, not your computed Fib value, and it
> will work.

yes, that works. Thank you.

>
> In general, CASE is not a very useful or used construct in Forth; this is
> not C. The less you use it, the better.
>

I see. How would you not use CASE, as I have done below:

: fib { n -- fibn }
  assert( n 0>= )
  n CASE
    0 OF 0 ENDOF
    1 OF 1 ENDOF
    2 OF 1 ENDOF        
    ( otherwise ) n 1 - recurse n 2 - recurse +
  SWAP ENDCASE ;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]