dc: Strings
1
1 8 Strings
1 *********
1
1 'dc' has a limited ability to operate on strings as well as on numbers;
1 the only things you can do with strings are print them and execute them
1 as macros (which means that the contents of the string are processed as
1 'dc' commands). Both registers and the stack can hold strings, and 'dc'
1 always knows whether any given object is a string or a number. Some
1 commands such as arithmetic operations demand numbers as arguments and
1 print errors if given strings. Other commands can accept either a
1 number or a string; for example, the 'p' command can accept either and
1 prints the object according to its type.
1
1 '[CHARACTERS]'
1 Makes a string containing CHARACTERS and pushes it on the stack.
1 For example, '[foo]P' prints the characters 'foo' (with no
1 newline). Note that all square brackets ('['s and ']'s) must be
1 balanced; there is no mechanism provided for handling unbalanced
1 square brackets.
1
1 'a'
1 The mnemonic for this is somewhat erroneous: asciify. The
1 top-of-stack is popped. If it was a number, then the low-order
1 byte of this number is converted into a 1-character string and
1 pushed onto the stack. Otherwise the top-of-stack was a string,
1 and the first character of that string is pushed back. (This
1 command is a GNU extension.)
1
1 'x'
1 Pops a value off the stack and executes it as a macro. Normally it
1 should be a string; if it is a number, it is simply pushed back
1 onto the stack. For example, '[1p]x' executes the macro '1p',
1 which pushes 1 on the stack and prints '1' on a separate line.
1
1 Macros are most often stored in registers; '[1p]sa' stores a macro
1 to print '1' into register 'a', and 'lax' invokes the macro.
1
1 '>R'
1 Pops two values off the stack and compares them assuming they are
1 numbers, executing the contents of register R as a macro if the
1 original top-of-stack is greater. Thus, '1 2>a' will invoke
1 register 'a''s contents and '2 1>a' will not.
1
1 '!>R'
1 Similar but invokes the macro if the original top-of-stack is not
1 greater (is less than or equal to) what was the second-to-top.
1
1 '<R'
1 Similar but invokes the macro if the original top-of-stack is less.
1
1 '!<R'
1 Similar but invokes the macro if the original top-of-stack is not
1 less (is greater than or equal to) what was the second-to-top.
1
1 '=R'
1 Similar but invokes the macro if the two numbers popped are equal.
1
1 '!=R'
1 Similar but invokes the macro if the two numbers popped are not
1 equal.
1
1 '?'
1 Reads a line from the terminal and executes it. This command
1 allows a macro to request input from the user.
1
1 'q'
1 During the execution of a macro, this command exits from the macro
1 and also from the macro which invoked it. If called from the top
1 level, or from a macro which was called directly from the top
1 level, the 'q' command will cause 'dc' to exit.
1
1 'Q'
1 Pops a value off the stack and uses it as a count of levels of
1 macro execution to be exited. Thus, '3Q' exits three levels.
1