(dc.info)Strings


Next: Status Inquiry Prev: Parameters Up: Top
Enter node , (file) or (file)node

8 Strings
*********

'dc' has a limited ability to operate on strings as well as on numbers;
the only things you can do with strings are print them and execute them
as macros (which means that the contents of the string are processed as
'dc' commands).  Both registers and the stack can hold strings, and 'dc'
always knows whether any given object is a string or a number.  Some
commands such as arithmetic operations demand numbers as arguments and
print errors if given strings.  Other commands can accept either a
number or a string; for example, the 'p' command can accept either and
prints the object according to its type.

'[CHARACTERS]'
     Makes a string containing CHARACTERS and pushes it on the stack.
     For example, '[foo]P' prints the characters 'foo' (with no
     newline).  Note that all square brackets ('['s and ']'s) must be
     balanced; there is no mechanism provided for handling unbalanced
     square brackets.

'a'
     The mnemonic for this is somewhat erroneous: asciify.  The
     top-of-stack is popped.  If it was a number, then the low-order
     byte of this number is converted into a 1-character string and
     pushed onto the stack.  Otherwise the top-of-stack was a string,
     and the first character of that string is pushed back.  (This
     command is a GNU extension.)

'x'
     Pops a value off the stack and executes it as a macro.  Normally it
     should be a string; if it is a number, it is simply pushed back
     onto the stack.  For example, '[1p]x' executes the macro '1p',
     which pushes 1 on the stack and prints '1' on a separate line.

     Macros are most often stored in registers; '[1p]sa' stores a macro
     to print '1' into register 'a', and 'lax' invokes the macro.

'>R'
     Pops two values off the stack and compares them assuming they are
     numbers, executing the contents of register R as a macro if the
     original top-of-stack is greater.  Thus, '1 2>a' will invoke
     register 'a''s contents and '2 1>a' will not.

'!>R'
     Similar but invokes the macro if the original top-of-stack is not
     greater (is less than or equal to) what was the second-to-top.

'<R'
     Similar but invokes the macro if the original top-of-stack is less.

'!<R'
     Similar but invokes the macro if the original top-of-stack is not
     less (is greater than or equal to) what was the second-to-top.

'=R'
     Similar but invokes the macro if the two numbers popped are equal.

'!=R'
     Similar but invokes the macro if the two numbers popped are not
     equal.

'?'
     Reads a line from the terminal and executes it.  This command
     allows a macro to request input from the user.

'q'
     During the execution of a macro, this command exits from the macro
     and also from the macro which invoked it.  If called from the top
     level, or from a macro which was called directly from the top
     level, the 'q' command will cause 'dc' to exit.

'Q'
     Pops a value off the stack and uses it as a count of levels of
     macro execution to be exited.  Thus, '3Q' exits three levels.


automatically generated by info2www version 1.2.2.9