Re: if then else - but why is there no =?windows-1255?b?kWVsc2WS?= in colorForth?
Nick Maroudas <[email protected]> Wed, 22 Oct 2008 12:40:30 +0200
| Newsgroups | gmane.comp.lang.forth.colorforth |
|---|---|
| Message-ID | <[email protected]> |
Quoting Jason Kemp <[email protected]>: >... " 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