Home   Archive   Permalink

Make a block with name supplied at run time

It seems like I should be able to do this. I want to read an unknown amount of data at run time, and depending on what I get I want to put it into one or more blocks, the names of which will be determined by the data itself. For example, some of the data might be for street names, and some header in the data will indicate this, perhaps by a header record containing the text STREETNAMES. So after reading this data and determining that it contains street names, I want to make a block called STREETNAMES and put data into that block. But the data might not be street names; I won't know until I actually read it, and so I want to pick the block name AFTER reading the data. I can't quite see how to do that, or if it can be done.
The reason I want to determine the block name at run time is that I want to make an arbitrary number of blocks. I could use, for example, six generic names like BLOCK1...BLOCK6, but then I might get a set of data that contains data for seven blocks. Being able to set the number of blocks and their names at run time gives generality.    
As an example, in the following script, I am prompted to enter a word that will become the name of a block. I get the name, but then what do I do with it to make it into the name of a block, and then to start adding data to the block?
Thank you.    
R E B O L []
BLOCKNAME: ask "Enter name for a new block: "
;to-set-word BLOCKNAME copy [] ;; This does not work
;to-set-word BLOCKNAME make block! ;; This does not work

posted by:   Steven White       23-Oct-2017/17:17-7:00

This would make a good StackOverflow question.
(When something is more conversational and less Q&A...e.g. the kind of thing StackOverflow prohibits...forums are good. But something like this is of general interest, and having access to Markdown formatting and being able to edit and improve posts is worthwhile.)
You will probably find the answer to this question illustrative, in particular the part after "But producing a SET-PATH! doesn't mean it runs."

posted by:   Fork       23-Oct-2017/18:26:51-7:00



Type the reverse of this captcha text: "t e s n i o j"