From 547bd9374725b8c64069f659b0efc4a3f128d855 Mon Sep 17 00:00:00 2001 From: crc Date: Thu, 14 Mar 2019 18:37:56 +0000 Subject: [PATCH] add some comments and tests to LightWeightFlowControl.forth FossilOrigin-Name: a9c76be4447552090853990e3e8adf73dabc5850a0349902a962df041ae70e60 --- example/LightWeightFlowControl.forth | 31 +++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/example/LightWeightFlowControl.forth b/example/LightWeightFlowControl.forth index 401e815..815e37d 100644 --- a/example/LightWeightFlowControl.forth +++ b/example/LightWeightFlowControl.forth @@ -1,8 +1,33 @@ +These are adapted from HerkForth. + + | 0= | n- | exit word if TOS = 0 | + | <; | nn- | exit word if NOS < TOS | + | >; | nn- | exit word if NOS > TOS | + | <>; | nn- | exit word if NOS <> TOS | + | if; | f- | exit word if TOS is TRUE | + | ?; | f- | exit word if TOS is TRUE. Leave Flag on stack if TRUE. | + ~~~ :0=; n:zero? [ as{ 'popopodr i 'drdrre.. i }as ] if ; -:< lt? [ as{ 'popopodr i 'drdrre.. i }as ] if ; -:> gt? [ as{ 'popopodr i 'drdrre.. i }as ] if ; -:<> -eq? [ as{ 'popopodr i 'drdrre.. i }as ] if ; +:<; lt? [ as{ 'popopodr i 'drdrre.. i }as ] if ; +:>; gt? [ as{ 'popopodr i 'drdrre.. i }as ] if ; +:<>; -eq? [ as{ 'popopodr i 'drdrre.. i }as ] if ; :if; [ as{ 'popopodr i 'drdrre.. i }as ] if ; :?; dup [ as{ 'popopodr i 'drdrre.. i }as ] if drop ; ~~~ + + +``` +:test (n-) n:even? if; 'Odd! s:put nl ; + +#1 test +#2 test +``` + + +``` +nl '----------------- s:put nl +:test (n-) n:even? ?; 'Odd! s:put nl ; +#1 test dump-stack reset nl +#2 test dump-stack reset nl +```