next up previous contents index
Next: Substrings Up: Using strings Previous: Using strings

Inserting strings

Wherever the name of a string appears in square brackets during [B/D] input, the name of the string is replaced by the string itself. Thus, for example, suppose that we have defined the strings a=xvariable1 and b2=intercept as above. Then the command

BD>print : We are about to print the value of [a] and [b2] tex2html_wrap_inline33712

is parsed, and the string names replaced, to obtain the command

BD>print : We are about to print the value of xvariable1 and intercept tex2html_wrap_inline33712

Unrecognised quantities in square brackets are not replaced. This thus allows the recursive definition of strings as in the sequence of commands

BD>string : a=[b][c] tex2html_wrap_inline33712

BD>string : b=text1 tex2html_wrap_inline33712

BD>string : c=text2 tex2html_wrap_inline33712

which would result in a later use of [a] being replaced by the characters `text1text2'. Another use of this feature allows us to store entire command lines as strings. Consider, for example, the following definition:

BD>string :t=print : This is an example! tex2html_wrap_inline33712

At a later stage we might issue simply the `command'

BD>[t] tex2html_wrap_inline33712

which, after parsing, will become equivalent to

BD>print : This is an example! tex2html_wrap_inline33712

Strings may be nested to any depth, limited only by line length. As an example, consider the following code:

BD>string : mouse=cat tex2html_wrap_inline33712

BD>string : cat=dog tex2html_wrap_inline33712

BD>print : [[mouse]] tex2html_wrap_inline33712

This fragment of code should print the text `dog' as tex2html_wrap_inline34278 .

In the context of inserting strings during the parsing of command lines, strings have lower precedence than all control variable names defined in active FOR:  statements. Thus the following legal sequence of commands:

BD>for : i=1,1,2 tex2html_wrap_inline33712

BD>string : i=7 tex2html_wrap_inline33712

BD>print : i=[i] tex2html_wrap_inline33712

BD>end : tex2html_wrap_inline33712

results in the output `i=1' and 'i=2', as the quantity `[i]' is replaced by the value of the control variable rather than the string.

See §1.4.2 for futher details on parsing.


next up previous contents index
Next: Substrings Up: Using strings Previous: Using strings

David Wooff
Wed Oct 21 15:14:31 BST 1998