\ ********************************************************************* 
\ CASE ENDCASE for ESP32Forth 
\    Filename:      caseEndcase.txt 
\    Date:          24 jan 2022 
\    Updated:       24 jan 2022 
\    File Version:  1.0 
\    MCU:           ESP32-WROOM-32 
\    Forth:         ESP32forth all versions 7.x++ 
\    Author:        Craig A. Lindley 
\    Adaptation:    Marc PETREMANN 
\    GNU General Public License 
\ ********************************************************************* 
 
 
\ *** Version to use for compiled ESP32Forth ************************* 
 
: ?dup dup if dup then ; 
internals 
: case 0 ; immediate 
: of ['] over , ['] = , ['] 0branch , here 0 , ['] drop , ; immediate 
: endof ['] branch , here 0 , swap here swap ! ; immediate 
: endcase ['] drop , begin ?dup while here swap ! repeat ; immediate 
 
 
 
\ *** Example of use: 
 
: jour. ( n -- ) 
    case 
        1 of ." lundi"      endof 
        2 of ." mardi"      endof 
        3 of ." mercredi"   endof 
        4 of ." jeudi"      endof 
        5 of ." vendredi"   endof 
        6 of ." samedi"     endof 
        7 of ." dimanche"   endof 
    endcase 
  ; 
 
 
 
\ *** Version of code to insert in .ino file *************************** 
\ search in .ino file line: 
\ ": aft   drop ['] branch , here 0 , here swap ; immediate\n" 
\ 
\ and insert these lines: 
 
 
" ( More Misc CAL words )\n" 
": ?dup dup if dup then ;\n" 
": between? ( n min-inc max-inc -- f ) rot >r r@ >= swap r> <= and ;\n" 
 
"( Case support )\n" 
": case 0 ; immediate\n" 
": of ['] over , ['] = , ['] 0branch , here 0 , ['] drop , ; immediate\n" 
": endof ['] branch , here 0 , swap here swap ! ; immediate\n" 
": endcase ['] drop , begin ?dup while here swap ! repeat ; immediate\n" 
 
 

Legal: site web personnel sans commerce / personal site without seling