Re: [colorforth] Fibonacci numbers
- Subject: Re: [colorforth] Fibonacci numbers
- From: Peter Appelman <peter@xxxxxxxxxxxxxxxxx>
- Date: Thu, 28 Nov 2002 10:28:00 -0500
- Mail-followup-to: colorforth@xxxxxxxxxxxxxxxxxx
On Wed, Nov 27, 2002 at 06:33:28PM -0500, Mark Slicker wrote:
> 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
>
Mark,
lets not stop there:
: fib push 1 dup pop -2 +
: f -if drop nip ; then push swap over + pop -1 + f ;
Regards,
Peter.
---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx