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

Yes, you can, in effect, redefine the behavior of a previously define
switch item. This is in contrast to redefining a FORTH word in which
only subsequent references to that word have different behavior. When
a switch is "redefined", all references to it are altered. This is
very handy for extending existing code
Again, back to the Win2.F application shell you could define
[+SWITCH APP-COMMANDS
M_EXIT RUNS MY-APP-EXIT ( ie Ask user if he is sure )
SWITCH]
anytime after Win2.F was INCLUDEd and redefine the behavior of the
"Exit" menu command.
Very handy.
Mike
----- Original Message -----
From: "Richard Owlett" <rowlett_at_atlascomm.net>
To: <sftalk_at_forth.com>
Sent: Monday, October 15, 2001 2:21 PM
Subject: [sftalk] Re: [SWITCH Example, was How to use funtions in
Ofn.f ?
>
> 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. ---------------------------------------------------------------------- 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 - 16:04:29 PDT
This archive was generated by hypermail 2.2.0 : Fri Nov 21 2008 - 03:04:19 PST