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

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
-------------------------------------------------
An excellent use of [+SWITCH is to process the WM_COMMAND messages in
the Win2.F example.
[+SWITCH APP-COMMANDS
111 RUN: FOO 0 ( res ) ;
112 RUN: BAR 0 ( res ) ;
SWITCH]
One can extend the SF command window message processing with something
like the following:
CONSOLE-WINDOW +ORDER
[+SWITCH SF-COMMANDS
1001 RUN: MY-SF-CMD 0 ( res ) ;
SWITCH]
CONSOLE-WINDOW -ORDER
----- Original Message -----
From: "Richard Owlett" <rowlett_at_atlascomm.net>
To: <sftalk_at_forth.com>
Sent: Sunday, October 14, 2001 12:22 PM
Subject: [sftalk] How to use funtions in Ofn.f ?
> I've had another problem. I hesitate to state it as a problem, as I
have
> not researched it enough to say "I can not solve this one." However,
it
> may illuminate a 'blind spot'.
> Although I'm currently avoiding using items defined in winmaker.f.
The
> use of "+SWITCH" escapes me.
----------------------------------------------------------------------
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 - 09:17:34 PDT
This archive was generated by hypermail 2.2.0 : Fri Nov 21 2008 - 03:04:19 PST