[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [gforth] attempt to use WHILE leads to empty stack (loop issues)
From: |
Bernd Paysan |
Subject: |
Re: [gforth] attempt to use WHILE leads to empty stack (loop issues) |
Date: |
Sat, 6 Mar 2010 20:52:43 +0100 |
User-agent: |
KMail/1.13.0 (Linux/2.6.31.12-0.1-default; KDE/4.4.0; x86_64; ; ) |
Am Samstag 06 März 2010 20:32:29 schrieb Terrence Brannon:
> : log2 ( +n1 -- n2 )
>
> assert( dup 0> )
> halve-n
> init-counter-for-number-of-halves-needed
> BEGIN
> insure-n-is-greater-than-or-equal-to-0
> WHILE \ n >= 0
> halve-n-and-increment-counter { n counter -- n/2 counter+1 }
Change these braces to parentheses, then it will work. What you are doing
here is declaring and initializing two local variables, which consume two
values on the stack.
> REPEAT
> NIP \ n, leaving the counter
> ;
--
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://www.jwdt.com/~paysan/
signature.asc
Description: This is a digitally signed message part.