I think I get it now. ?OF should actually find 2 numbers on the stack, viz., the number being tested by CASE and the flag. I have not yet tested what follows, but I think it will work. The idea of the code is to toggle the flag and add it to a duplicate of the test number before presenting it to OF . A false flag will then force a mismatch, while a true flag will force a match. It must be paired with ENDOF .
Here it is for Camel99 Forth:
: ?OF \ compile-time: ( 4 -- here 5 ) run-time: ( n flag -- |n) \ toggling flag will force proper match/mismatch for OF POSTPONE 0= POSTPONE OVER POSTPONE + \ S:n flag'+n POSTPONE OF ; IMMEDIATE
Here is the equivalent fbForth version:
: ?OF \ compile-time: ( 4 -- here 5 ) run-time: ( n flag -- |n) \ toggling flag will force proper match/mismatch for OF COMPILE 0= COMPILE OVER COMPILE + \ S:n flag'+n [COMPILE] OF ; IMMEDIATE
Here is an example of its use (block #41 of FBLOCKS must be loaded to use WITHIN ):
: XX ( n -- ) CASE DUP 2 9 WITHIN ?OF ." In range (2,9)." ENDOF ELSEOF ." No match!" ENDOF ENDCASE ;
[Edits in this color.]