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

Experimenting seems to show that
[SWITCH SHOW-ME NOT-SPECIAL
0 RUN: CR ." Zero" ;
1 RUN: CR ." One" ;
DUAL RUN: CR ." Two" ;
3 RUNS THREE
4 RUNS FOUR
SWITCH]
.
.
.
intervening code
.
.
.
[+SWITCH SHOW-ME
1 RUN: CR ." a different message" ;
6 RUN: CR ." a Six" ;
SWITCH]
is legal. Is that correct? Does it correspond to be allowed to give a
new definition to a previously defined word, with the same
effects/restrictions?
Mike Ghan wrote:
>
> Richard, a simple example of [SWITCH
>
> -----------------------------------------------------
>
> \ A few example words
> : THREE ( -- ) CR ." Three" ;
> : FOUR ( -- ) CR ." Four" ;
>
> 2 CONSTANT DUAL
>
> \ This is our default handler
> : NOT-SPECIAL ( n -- ) CR ." Nothing Special: " . ;
>
> \ We define a switch structure with a default behavior
> \ Note that the numbers before RUNS or RUN: must be fixed
> \ at compile time. You can't use a VALUE that changes.
> [SWITCH SHOW-ME NOT-SPECIAL
> 0 RUN: CR ." Zero" ;
> 1 RUN: CR ." One" ;
> DUAL RUN: CR ." Two" ;
> 3 RUNS THREE
> 4 RUNS FOUR
> SWITCH]
>
> \ More examples
> : FIVE ( -- ) CR ." Five" ;
>
> \ Now we'll extend the switch structure
> [+SWITCH SHOW-ME
> 5 RUNS FIVE
> 6 RUN: CR ." a Six" ;
> SWITCH]
>
> \ Test
> 1 SHOW-ME
> 3 SHOW-ME
> 9 SHOW-ME
>
> <SNIP>
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/sftalk -- check them out!
Search the archives! Visit http://www.forth.com/search for details.
Received on Mon Oct 15 2001 - 14:25:34 PDT
This archive was generated by hypermail 2.2.0 : Fri Nov 21 2008 - 03:04:19 PST