"Beginning installation of lib-case... @prog lib-case 1 99999 d 1 i ( lib-case: $Date: 2001/02/23 16:04:38 $ $Revision: 1.5 $ Originally from FuzzBall MUF distribution ) ( --------------------------------------------------------------------------- ) ( Okay, here's an evil idea for you programmers: Fringe came up with a truly demented way to get case statements using just $defines, so we made it into a library. The library basically makes the following defines: -------- $define case begin dup $enddef $define when if pop $enddef $define end break then dup $enddef $define default pop 1 if $enddef $define endcase pop pop 1 until $enddef -------- And what it lets you do is something like this: -------- $include $lib/case case when end when end when end when end default end endcase -------- This will compile to the following: -------- begin dup if pop break then dup if pop break then dup if pop break then dup if pop break then dup pop 1 if break then dup pop pop 1 until -------- The default clause is optional and thats why the wierd 'dup pop pop' is at the end. The clause is passed the value that failed to match in any of the tests. The can be as complex as you wish, and so can the and statements. Here's an example using real code: -------- read case "#help" over stringcmp not swap "#h" stringcmp not or when do-help end "#help2" over stringcmp not swap "#h2" stringcmp not or when do-help2 end "#list" stringcmp not when do-list end default pop give-error end endcase -------- Enjoy! - Foxen ) ( --------------------------------------------------------------------------- ) ( $Log: lib-case,v $ Revision 1.5 2001/02/23 16:04:38 feaelin Fixed Link_OK setting Revision 1.4 2000/02/11 15:10:47 feaelin Wasn't properly set link_ok. Revision 1.3 1999/02/13 16:35:17 feaelin Make that two. Revision 1.2 1999/02/13 16:33:02 feaelin Ooops. missing paren. Revision 1.1 1998/08/23 16:27:17 glow Initial revision ) : main "" pop ; . c q @register lib-case=lib/case @register #me lib-case=tmp/prog1 @set $tmp/prog1=L @set $tmp/prog1=/_/de:lib-case: List lines 1-50 for documentation. @set $tmp/prog1=/_defs/case:begin dup @set $tmp/prog1=/_defs/default:pop 1 if @set $tmp/prog1=/_defs/end:break then dup @set $tmp/prog1=/_defs/endcase:pop pop 1 until @set $tmp/prog1=/_defs/when:if pop @set $tmp/prog1=/_docs:@list $lib/case=1-50 @set $tmp/prog1=/_lib-version:FM$Revision: 1.5 $ "Installation of lib-case completed.