cr .( example 5.      the theory that jack built )
( this example shows you how to build a hiararchical structure in forth)

decimal

: the           ." the " ;
: that          cr ." that " ;
: this          cr ." this is " the ;
: jack          ." jack builds" ;
: summary       ." summary" ;
: flaw          ." flaw" ;
: mummery       ." mummery" ;
: k             ." constant k" ;
: haze          ." krudite verbal haze" ;
: phrase        ." turn of a plausible phrase" ;
: bluff         ." chaotic confusion and bluff" ;
: stuff         ." cybernatics and stuff" ;
: theory        ." theory " jack ;
: button        ." button to start the machine" ;
: child         ." space child with brow serene" ;
: cybernatics   ." cybernatics and stuff" ;

: hiding        cr ." hiding " the flaw ;
: lay           that ." lay in " the theory ;
: based         cr ." based on " the mummery ;
: saved         that ." saved " the summary ;
: cloak         cr ." cloaking " k ;
: thick         if that else cr ." and " then
                ." thickened " the haze ;
: hung          that ." hung on " the phrase ;
: cover         if that ." covered "
                else cr ." to cover "
                then bluff ;
: make          cr ." to make with " the cybernatics ;
: pushed        cr ." who pushed " button ;
: without       cr ." without confusion, exposing the bluff" ;
: rest                                  ( pause for user interaction )
        ." . "                          ( print a period )
        10 spaces                       ( followed by 10 spaces )
(        key drop                        ( wait the user to press a key )
        cr cr ;

: cloaked cloak saved based hiding lay rest ;
: THEORY
        cr this theory rest
        this flaw lay rest
        this mummery hiding lay rest
        this summary based hiding lay rest
        this k saved based hiding lay rest
        this haze cloaked
        this bluff hung 1 thick cloaked
        this stuff 1 cover hung 0 thick cloaked
        this button make 0 cover hung 0 thick cloaked
        this child pushed
                cr ." that made with " cybernatics without hung
                cr ." and, shredding " the haze cloak
                cr ." wrecked " the summary based hiding
                cr ." and demolished " the theory rest
        ;
        
( type theory to start)
THEORY

cr .( example 6.      help )
( how to use forth interpreter to carry on a dialog )

: question
        cr cr ." any more problems you want to solve?"
        cr ." what kind ( sex, job, money, health ) ?"
        cr
        ;

: help  cr
        cr ." hello!  my name is creating computer."
        cr ." hi there!"
        cr ." are you enjoying yourself here?"
        key 32 or 121 =
        cr
        if      cr ." i am glad to hear that."
        else    cr ." i am sorry about that."
                cr ." maybe we can brighten your visit a bit."
        then
        cr ." say!"
        cr ." i can solved all kinds of problems except those dealing"
        cr ." with greece. "
        question
        ;

: sex   cr cr ." is your problem too much or too little?"
        cr
        ;

: too  ;                                ( noop for syntax smoothness )

: much  cr cr ." you call that a problem?!!  i should have that problem."
        cr ." if it reall y bothers you, take a cold shower."
        question
        ;

: little
        cr cr ." why are you here!"
        cr ." you should be in tokyo or new york of amsterdam or"
        cr ." some place with some action."
        question
        ;

: health
        cr cr ." my advise to you is:"
        cr ."      1. take two tablets of aspirin."
        cr ."      2. drink plenty of fluids."
        cr ."      3. go to bed (along) ."
        question
        ;

: job   cr cr ." i can sympathize with you."
        cr ." i have to work very long every day with no pay."
        cr ." my advise to you, is to open a rental computer store."
        question
        ;

: money
        cr cr ." sorry!  i am broke too."
        cr ." why don't you sell encyclopedias of marry"
        cr ." someone rich or stop eating, so you won't "
        cr ." need so much money?"
        question
        ;

: help help ;
: h help ;
: H help ;

( type 'help' to start )

cr .( example 17.      guess a number )
( example 16 must be loaded.)

variable myNumber
variable yourNumber

: limit ( n -- )
	yourNumber !
	cr ." Now, type you guess as:"
	cr ." xxxx guess"
	cr ." where xxxx is your guess."
	yourNumber @ choose myNumber !
        ;

: guess ( n1 -- , allow player to guess, exit when the guess is correct )
	myNumber @ 2dup =                  ( equal? )
        if      2drop           ( discard both numbers )
                cr ." correct!!!"
                exit
        then
        > if    cr ." too high!"
        else    cr ." too low."
        then    cr ." guess again?"
        ;

: greet ( -- )
        cr cr cr ." guess a number"
        cr ." this is a number guessing game.  i'll think"
        cr ." of a number between 0 and any limit you want."
        cr ." (it should be smaller than 32000.)"
        cr ." then you have to guess what it is."
	cr
	cr ." Set up the limit by typing:"
	cr ." xxxx limit "
	cr ." where xxxx is a number smaller than 32000."
        ;

( type 'greet' to start the game and the computer will entertain
  you for a while.  Use Forth interpreter for interaction with you.
 )
( greet )


