-
Notifications
You must be signed in to change notification settings - Fork 9
Tour
Wolf Wejgaard edited this page Jun 18, 2023
·
17 revisions
TclForth changes the standard Forth command line just a little:
Strings need no space after the first "
"Hello World"
({Hello World}) ok
. cr
Hello World
ok
The command line evaluates immediate words.
7 0 do I . loop
0 1 2 3 4 5 6 ok
ok
Stack diagrams are enclosed in braces.
: Star { -- } "*" . ;
ok
Star
* ok
Stack parameters are local variables.
: Stars { n -- } n times Star repeat ;
ok
5 Stars
* * * * * ok
: Grid { n m -- } n times m Stars cr repeat ;
ok
3 4 Grid
* * * *
* * * *
* * * *
ok
Say, you want to print the stars without trailing spaces: redefine Star and keep the later words Stars and Grid. {} denotes an empty stack.
: Star {} "*" ascii emit ;
ok
3 4 Grid
****
****
****
Tcl replaces code in a loaded word. The change is active for all dependent words. - You can change a running TclForth program.
TclForth uses the variable substitutions of Tcl.
33 variable V
ok
"The value of V is $V" . cr
The value of V is 33
ok
Changing the GUI: Add a command to the help menu.
: SayHello {} "Hello TclForth!" . cr ;
"Hello!" {SayHello} hMenu addcommand