ForthNet@willett.UUCP (ForthNet articles from GEnie) (01/08/90)
Date: 01-06-90 (14:24) Number: 497
To: GORDON GANDERTON Refer#: NONE
From: DAVE BROWN Read: NO
Subj: INPUT EXAMPLE Status: PUBLIC MESSAGE
I found an example of what you want to do in Brodie's Starting Forth.
Here it is:
CREATE USER-NAME 40 ALLOT \ A space for holding the user's name
: .USER ( -- )
USER-NAME \ Put Address of User's name on stack
40 -TRAILING \ Remove any blank spaces at end of name
TYPE ; \ Type the user's name.
: GET-NAME ( -- )
USER-NAME 40 BLANK \ Clear user's name field of junk
USER-NAME 40 EXPECT ; \ "Expect" 40 characters into USER-NAME
: GREET ( -- )
CR ." Please type your name: "
GET-NAME \ Get user's name
CR ." Hello, " .USER ." , I speak Forth. " ;
This produces:
GREET <Enter>
Please type your name: <TRAVIS MC GEE> <Enter>
Hello, TRAVIS MC GEE, I speak Forth.
Expect can be used for inputing strings. I'm not sure what F-PC's limit
is on the number of characters to expect, but I do know that it has some
line editing capabilities built in. (Insert, Delete, Etc).
I found this example on page 239 of Starting Forth 2nd Ed, but I'm
fairly sure that it is also in his 1st edition.
Hope this helps,
..Dave
NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886
-----
This message came from GEnie via willett through a semi-automated program.
Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'