Question load function (I think)
I am making a little command processor to run on a server. The current plan is that the command will be a string containing a command word followed by various REBOL values that vary depending on the command word. A sample follows. If the command line has several values and I 'load' it, I get a block of those values. But, if the command line is a command that needs just the command word and nothing following, and I load the line, the result is a word. In other words, NOT a block with the first (and only) item being the command word. I would like to find a way to 'load' the command line so that the result is the same no matter how many values are on the line. I could use parse, as shown in the example. If I do that, the result is a block, but each item in the block is a string, which means I have to do some conversion (not a big deal) and that I lose the smoothness of the REBOL-recognized values. Is there a third option I am missing? Thank you. Sample: R E B O L [ ] MSG-MULTIWORD: {notice %test.txt 'notice text'} MSG-SINGLEWORD: {quit} PARTS-MULTIWORD: load MSG-MULTIWORD PARTS-SINGLEWORD: load MSG-SINGLEWORD PARSED-MULTIWORD: parse MSG-MULTIWORD none print ['PARTS-MULTIWORD is a ' type? PARTS-MULTIWORD] print ['PARTS-MULTIWORD/1 is a ' type? PARTS-MULTIWORD/1 ' = ' PARTS-MULTIWORD/1] print ['PARTS-MULTIWORD/2 is a ' type? PARTS-MULTIWORD/2 ' = ' PARTS-MULTIWORD/2] print ['PARTS-MULTIWORD/3 is a ' type? PARTS-MULTIWORD/3 ' = ' PARTS-MULTIWORD/3] print '-----------------------' print ['PARTS-SINGLEWORD is a ' type? PARTS-SINGLEWORD] print '-----------------------' print ['PARSED-MULTIWORD is a ' type? PARSED-MULTIWORD] print ['PARSED-MULTIWORD/1 is a ' type? PARSED-MULTIWORD/1 ' = ' PARSED-MULTIWORD/1] print ['PARSED-MULTIWORD/2 is a ' type? PARSED-MULTIWORD/2 ' = ' PARSED-MULTIWORD/2] print ['PARSED-MULTIWORD/3 is a ' type? PARSED-MULTIWORD/3 ' = ' PARSED-MULTIWORD/3] print '-----------------------' halt Result: PARTS-MULTIWORD is a block PARTS-MULTIWORD/1 is a word = notice PARTS-MULTIWORD/2 is a file = test.txt PARTS-MULTIWORD/3 is a string = notice text ----------------------- PARTS-SINGLEWORD is a word ----------------------- PARSED-MULTIWORD is a block PARSED-MULTIWORD/1 is a string = notice PARSED-MULTIWORD/2 is a string = %test.txt PARSED-MULTIWORD/3 is a string = notice text -----------------------
posted by: Steven White 11-Dec-2015/17:02:57-8:00
You can use 'to-block: >> MSG-MULTIWORD: to-block {notice %test.txt 'notice text'} == [notice %test.txt 'notice text'] >> MSG-SINGLEWORD: to-block {quit} == [quit] You can also use 'to-block to convert the values assigned to the words, after they've been defined: MSG-MULTIWORD: {notice %test.txt 'notice text'} MSG-SINGLEWORD: {quit} probe to-block MSG-MULTIWORD probe to-block MSG-SINGLEWORD
posted by: Nick 11-Dec-2015/20:48:36-8:00
Load/all is what you are looking for.
posted by: MarkI 12-Dec-2015/7:46:08-8:00
|