Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Forth > confusing bit i...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 3787 of 4173
Post > Topic >>

confusing bit in ch4 of starting forth

by gavino <gavcomedy@[EMAIL PROTECTED] > Feb 29, 2008 at 12:08 PM

from http://www.forth.com/starting-forth/sf4/sf4.html

Here's a more useful example. You know that dividing any number by
zero is impossible, so if you try it on a computer, you'll get an
incorrect answer. We might define a word which only performs division
if the denominator is not zero. The following definition expects stack
items in this order:
    ( numerator denominator -- quotient )
    : /CHECK
      DUP 0= IF  ." invalid " DROP
           ELSE /
           THEN ;


Notice that we first have to DUP the denominator because the phrase
    0= IF

will destroy it in the process.

Also notice that the word DROP removes the denominator if division
won't be performed, so that whether we divide or not, the stack effect
will be the same.



The last two sentances confuse me.....can someone walk me through what
the stack does? There seems to be a paradox where 0= destroys the
denominator but DUPE is  still needed to destory it?

0
10

0
0
10
 




 4 Posts in Topic:
confusing bit in ch4 of starting forth
gavino <gavcomedy@[EMA  2008-02-29 12:08:18 
Re: confusing bit in ch4 of starting forth
Frank Buss <fb@[EMAIL   2008-02-29 23:01:23 
Re: confusing bit in ch4 of starting forth
Jonah Thomas <jethomas  2008-02-29 17:19:02 
Re: confusing bit in ch4 of starting forth
gavino <gavcomedy@[EMA  2008-02-29 14:49:04 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 17:08:23 CDT 2008.