carr@utah-cs.UUCP (Harold Carr) (09/14/84)
I am new to forth. Could someone tell me how to do this
in Princeton's VaxForth?:
When loading a file that contains:
8 len data
I want 8 to be pushed (as it will be) and LEN to be defined
such that it has the effect:
here constant data allot ( with allot getting its parameter)
( from the previous push of 8)
In other words, I want to dynamically create a constant whose name
is taken from the input stream.
Any help would be much appreciated.
Harold Carr
arpa: CARR@UTAH-20
uucp: harpo!utah-cs!carrcarr@utah-cs.UUCP (Harold Carr) (09/19/84)
Thank you. Before I received your answer I had looked up the code
defining ARRAY in forth.blk and used it as a model for this definition
of LEN:
: LEN ( n --- )
HERE 1 AND ALLOT ( even up the address)
CREATE ( get segment name from input stream)
HERE ( beginning of storage for segment)
SWAP DUP ALLOT ( allocate N byte of storage)
0 FILL ; ( initialize storage to zero)
Being new to forth, while I was rummaging through the documention for
useful words to define defining words, it was not clear to me at all that:
--------------------------------------------------
CREATE
A defining word used in the form:
CREATE <name>
to create a dictionary entry for <name>, without allocating any
parameter field memory. When name is subsequently executed, the address
of the first byte of <name>'s parameter field is left on the stack.
--------------------------------------------------
got <name> from the input stream. Even the page on notation says nothing,
so I really appreciate how you pointed out your convention for notating
this. Also, thanks for pointing out the use of DOES> in this context.
Even though my header said DYNAMIC CONSTANTS you cleary saw through
this to see what I was really trying to do was to make a defining
word for byte arrays.
Thank you very much for your help,
Harold Carr
-------