home *** CD-ROM | disk | FTP | other *** search
Null Bytes Alternating | 1995-05-19 | 6.5 KB | 124 lines |
- \ case.utf ..
- \ implement CORE EXTENSIONS construct CASE .. OF .. ENDOF .. ENDCASE
- \ ANS Forth compliant source code is Copyright (c)1994 by
- \ Jack J. Woehr, P.O. Box 51, Golden, Colorado 80402-0051
- \ jax@well.sf.ca.us 72203.1320@compuserve.com
- \ SYSOP RCFB (303) 278-0364 2400/9600/14400
- \ All Rights Reserved
- \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- \ This is free software and can be modified and redistributed under
- \ certain conditions described in the file COPYING.TXT. The
- \ Disclaimer of Warranty and License for this free software are also
- \ contained in the file COPYING.TXT.
- \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- \
- \ $Revision: 1.3 $
- \
-
- \ There persists a standard system after loading CASE.UTF.
- MARKER case.utf
-
- \ Dependencies:
- \ For infotext display while loading this file, and for its particular handling
- \ of the compilation vocabulary into which non-Standard factors are deposited,
- \ but for no algorithm of substance, this file is dependent upon the material
- \ in //jax4th/utils/.
-
- \ ~~~~~~~~~~~~~~~~~~~~
- \ Conditional INCLUDED
- \ ~~~~~~~~~~~~~~~~~~~~
-
- : PROVIDES ( c-addr u "ccc< >" --)
- BL WORD FIND NIP 0=
- IF INCLUDED ELSE 2DROP THEN ;
-
- S" UTILS\UTILS.UTF" PROVIDES USEFUL
-
- .( Now loading CASE construct.) CR
-
- \ ifdef (wordlists to hide thingies like \vvvv/) {
- USEFUL
- NONSTANDARD-WORDLIST SET-CURRENT
- \ }endif
-
- \ A factoring of how CASE handles the case selector.
- : TRUTH|DARE ( x1 x2 -- [x1 FALSE] | TRUE)
- OVER = \ -- x1 flag
- IF \ -- x1
- DROP TRUE \ -- TRUE
- ELSE \ -- x1
- FALSE \ -- x1 FALSE
- THEN
- ;
-
- \ ... ['] THEN ... is not a legal construct: xt's returned
- \ by ticking Standard words possessing special compilation
- \ semantics aren't guaranteed to be useful in any particular context.
- : ]THEN[ POSTPONE THEN ;
- \ See ENDOF
-
- \ ifdef (wordlists to hide thingies like /^^^^\) {
- FORTH-WORDLIST SET-CURRENT
- \ }endif
-
- : OF ( C: -- of-sys) ( Runtime: x1 x2 -- |x1)
- POSTPONE TRUTH|DARE POSTPONE IF ; IMMEDIATE
-
- : ENDOF ( C: case-sys1 of-sys -- case-sys2) ( Runtime: --)
- POSTPONE EXIT
- ['] ]THEN[ \ but this is legal, see ]THEN[
- CATCH \ This is not terribly useful yet in Jax4th
- ?DUP \ but this is the correct way this should
- IF \ be done in Standard Forth.
- DUP \ In general the caller of a POSTPONE'd control
- ." ENDOF THROWs " .
- THEN \ construct should intercept any compile-time errors
- ; IMMEDIATE \ incurred in the course of such special handling.
-
- : ENDCASE ( C: case-sys --) ( Runtime: x --)
- POSTPONE DROP ; IMMEDIATE
-
- : CASE ( C: -- case-sys) ; IMMEDIATE
-
- \ ifdef wordlists {
- USEFUL
- \ } endif
-
- \ ~~~~~~~~~~~~
- \ An example
- \ ~~~~~~~~~~~~
-
- BASE @ DECIMAL
-
- : ((CASE-TEST)) ( x -- )
- CASE
- 0<
- TRUE OF ." (negative)" ENDOF
- ." (positive)"
- ENDCASE
- ;
-
- : (CASE-TEST) ( x -- )
- CASE
- 0 OF ." Zero" ENDOF
- DUP ((CASE-TEST))
- ENDCASE
- ;
-
- : CASE-TEST ( x -- )
- CASE
- DUP .
- 1 OF ." ONE " ENDOF
- 2 OF ." TWO " ENDOF
- DUP (CASE-TEST) \ default
- ENDCASE ( x --)
- ;
-
- BASE !
-
- \ ~~~~~~~~~~~~~~~~~
- \ End of CASE.UTF
- \ ~~~~~~~~~~~~~~~~~
-
-