![]() |
||
| Home | SwiftForth Archive | SwiftX Archive | |

Glenn,
Nope, you're not dumb; I'm just a little hasty.
The standard case statement can easily be extended by
mimicing the (OF) and OF words to do what you want:
-------------------------------------------------------------------------
\ extend the CASE ... OF .. ENDOF ... ENDCASE statement
\ needs better names
ICODE (CONDOF) ( x1 x2 -- x1 x2 | x1 )
EBX EBX OR 0= IF \ compare tos to itself
0 [EBP] EBX MOV \ not zero, so drop tos
4 # EBP ADD \ and leave x1
HERE $400 + JMP \ and take the unconditional jump
THEN \
RET END-CODE
: COND ( -- ofsys )
POSTPONE (CONDOF) (BEGIN) POSTPONE 2DROP ; IMMEDIATE
\ test the construct
: TEST ( n2 n3 -- ) LOCALS| n3 n2 |
CR ." n3 is " n3 . ." , n2 is " n2 . ." : "
0 CASE
n3 n2 = COND ." n3 == n2 " ENDOF
n3 n2 > COND ." n3 > n2 " ENDOF
n3 n2 < COND ." n3 < n2 " ENDOF
( default) ." shouldn't ever get here"
ENDCASE ;
-------------------------------------------------------------------------
Tuesday, April 29, 2003, 11:53:24 AM, you wrote:
rvn>>Inside a definition, use a CASE OF ENDOF ENDCASE
GD> statement to achieve this.
GD> I'm sorry, I use CASE all the time but must be dumb. How does one use
GD> it to test for multiple ANDed and ORed conditions instead of testing a
GD> single number on the stack? Would it be something like
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and bug
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Tue Apr 29 2003 - 13:52:50 PDT
This archive was generated by hypermail 2.2.0 : Wed Jan 07 2009 - 03:04:08 PST