[colorforth] Fibonacci numbers
- Subject: [colorforth] Fibonacci numbers
- From: Mark Slicker <maslicke@xxxxxxxxxxx>
- Date: Wed, 27 Nov 2002 18:33:28 -0500 (EST)
Hello,
Not too long ago Chuck said 'less' was obsolete. One use is in loop
termination, decrementing a number and checking a condition. Here I
provide a example of computing fibonacci numbers with 'less' and with
'-if' for comparison.
With 'less':
: fib push 1 dup pop
: f 2 less drop if drop nip ; then -1 + push swap over + pop f ;
With '-if'
: fib push 1 dup pop
: f -2 + -if drop nip ; then 1 + push swap over + pop f ;
There is not a large difference here, but the second is clearly simpler,
and does corespond more to the virtual machine, replacing words with
primitive operations.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx