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