|
From: | Elko Tchernev |
Subject: | Re: [gforth] naive fibonacci |
Date: | Sun, 07 Mar 2010 15:07:07 -0500 |
User-agent: | Thunderbird 2.0.0.23 (Windows/20090812) |
Terrence Brannon wrote:
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 ;
Something like this: : fib ( n -- fib ) DUP 0= IF EXIT THEN DUP 1 = IF EXIT THEN DUP 2 = IF 1- EXIT THEN DUP 1- RECURSE SWAP 2 - RECURSE + ;By the way, for some reason I don't receive my own messages to the list. The only way I see that they have been sent, is when someone replies to them. I checked my options in the list subscription pages, and they are properly set - I should receive my own messages, but I don't. Anybody having the same problem, or can offer some insight into what's going on?
[Prev in Thread] | Current Thread | [Next in Thread] |