args-brace:dstrings — immediate primitive
FORTH
ARGS{
( arg1'$ ... argN'$ "arg1 ... argN <}>" -- )( | ) ; |
; |
compilation: ( -- $: arg1$ ... argN$ )
Immediate and compilation-only.
Copy the argument strings to the string buffer, push them onto the string stack with "argN" the most accessible, and make them into the top compile-time string stack frame. Compile the run-time code to make an argument frame out of the N most accessible run-time string stack entries. Inform the system text interpreter that it should compile run-time code for any white-space delimited argument encountered in the text of the definition, that concatenates the corresponding string in the run-time frame. At the semicolon terminating the definition, drop the compile-time argument frame and compile code to drop the run-time argument frame. <ansref>"args-brace"</ansref>
Syntax for defining a string macro GEORGE:
: george ($: a$ b$ c$ -- cat$ ) args{ arg1 arg2 arg3 } cat" This is arg1: " arg1 cat" ." ENDCAT ;
The blank following the last argument is required. For a macro with no arguments, ARGS{ } does nothing but add useless overhead and should be omitted. Two of the arguments in this example are ignored and could have been left out. Words intended only as steps in building a macro would omit ENDCAT, which terminates concatenation and leaves the concatenated string on the string stack.
Sample syntax using the string macro GEORGE:
$" bill" $" sue" $" marie" george $.
The resulting display is:
This is arg1: bill.
NOTE: Macro argument labels must be distinct from each other and from any local labels that appear in the same definition, and there is no check for that.
NOTE: At the moment the semantics of ARGS{ is undefined before DOES>.