Re: [colorforth] if then else - but why is there no ‘else’ in colorForth?
- Subject: Re: [colorforth] if then else - but why is there no ‘else’ in colorForth?
- From: Nick Maroudas <alice@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 22 Oct 2008 12:40:30 +0200
Quoting Jason Kemp <jason.kemp@xxxxxxxxxxxxxxxx>:
>... " Hi Nick,
>... "
>... " ( n) : word1 dup ( nn) -1 + drop ( n) 0if (
>... " n,f) drop 1 ( no ";" ) then ( n/1) dup ( nn/11)
>... " -2 + drop 2 then (still no ";") 3 + ;
>... "
>... "
>... " But each ‘then’ has to match an ‘if’ so this
>... " can’t work can it?
>... "
Nick here: Sorry for the typo, of course it can't
work!
Here (I hope) is a correct version: this one should
act
to yield 1 if
n is 1 or else yield 2 if n is 2, then for any other
value of n it should yield n+3.
( n) : word1 dup ( nn) -1 + drop ( n) 0if ( n,f)
drop -2 ( no ";" ) then ( n/1) dup ( nn/11) -2 + drop
0if -1 (still no ";") then 3 + ;
But is this what is meant by "if-else-then" ?
Thank you for the explanation of how "if" works. I
shall try to digest it then post an example with 2
words as you suggest - this time with a " ; " between
"if" and "then" (if;else;then ?).
Also, re 'then' has to match an 'if', there are 2
'then' matched with only 1 'if' in the definition of '
+! ' (on block 26 of CF05). I have noticed such multi
concatenations elsewhere in CF. Perhaps the structure
of 'if' in CF is different from previous Forth,
allowing one to build multi choice equivalents of
'if;else;then' or 'case' ?
Caritas,
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx
Main web page - http://www.colorforth.com