This listing is a log of an interactive demonstration run. The indented lines are inputs to the Forth system, and the non-indented lines are the output from the Forth system.
VARIABLE X 1 X ! \ make some variables... VARIABLE Y 2 Y ! VARIABLE Z 3 Z ! : ? @ . ; ( variable -- ) \ print the value of a variable : DOT ( n -- ) \ another way to print a number 0 <# # # # # #> \ with leading zeros TYPE CR ; \ and a carriage return NIL VAR[ X Y ] DREAM snooze \ a dream about a couple of variables ESSENCE snooze RELAPSE nap \ a different version of the same dream { X ? Y ? Z ? } THOUGHT hmm \ a thought about 3 variables hmm STUPOR \ ponder it in reality 1 2 3 hmm snooze \ and again in a dream 1 2 3 100 X ! \ change the variables 200 Y ! 300 Z ! hmm STUPOR \ ponder it again in reality 100 200 300 hmm snooze \ and again in the dream 1 2 300 { 10 X ! 20 Y ! 30 Z ! } snooze \ make a change in the dream hmm snooze \ what was the effect? 10 20 30 hmm STUPOR \ what was the effect on reality? 100 200 30 hmm nap \ what is the other dream thinking? 1 2 30 NIL REF[ . ] TRANCE FUE \ a class of dreams about a colon definition FUE FOO \ a dream of that class FUE BAR \ another dream of the same class hmm FOO \ try it out 100 200 30 hmm BAR \ try that one too 100 200 30 ' DOT ' . ESSENCE FOO IMAGINE \ imagine that . behaves differently hmm FOO \ exhibit the new behavior 0100 0200 0030 hmm BAR \ show that BAR was unaffected 100 200 30 { hmm BAR } FOO \ a dream within a dream 100 200 30 { hmm FOO } snooze \ same dream, but within a different dream 0010 0020 0030 { { hmm BAR } FOO } snooze \ this can go as far as you like! 10 20 30 { hmm nap } FOO \ showing FOO's . still holds in nap 0001 0002 0030 { hmm REGRESS } FOO \ regress back from foo to reality 100 200 30 { { hmm nap } REGRESS } FOO \ more advanced navigation of the dream world 1 2 30 { X ? } snooze \ show snooze's understanding of the variable 10 { REALLY X ? } snooze \ show early binding to a variable 100 { X @ . } FOO \ show FOO's understanding of . 0100 { X @ REALLY . DID } FOO \ show early binding to a colon definition 100 VISION[ BAR FOO snooze ] BAZ \ make a vision to show how that works hmm BAZ \ should be same as: 10 20 30 \ { { hmm BAR } FOO } snooze VISION[ FOO BAR snooze ] BOK \ should print with leading zero hmm BOK \ try it and see 0010 0020 0030 hmm ESSENCE snooze SEE \ test of atomic dream passed to SEE 10 20 30 VISION[ FOO BAZ ] BACH \ make a nested dream hmm BACH \ test of a nested dream 0010 0020 0030 VISION[ FOO COMA BACH ] HANDEL \ doubly nested dream with null in middle hmm HANDEL \ try that one on for size! 0010 0020 0030 VISION[ BAR HANDEL ] MOZART \ exception link to override FOO hmm MOZART \ show that it works 10 20 30 { hmm REALITY } HANDEL \ test reality word 100 200 30