Dc

The unix dc(1) command, this is the esoteric language that "made it big". Originally written in assembler for Unix V1 it was translated to C for Version 7 Unix and paired with a wrapper bc(1) that changed it from a desktop calculator (like the HP-48) to a better calculator for mere mortals. This wrapper meant it became frequently used on many Unix versions despite many users never seeing it.

All numbers are unbounded and may have a specified number of digits in the fractional part.

Standard commands
This table documents the standard commands as they appeared in the V7 Unix version.

State commands
These commands change global state variables in the V7 Unix version's interpreter.

Additional commands
These commands are common to most current versions of dc(1).

GNU Extensions
This command is specific to the GNU version

BSD Extensions
These commands are specific to the BSD version

Named stacks
The same variables are referenced by all the " " commands, this gives some interesting effects.

The named variables are initially empty. The " " command will store a value onto the top of stack, creating the TOS if it doesn't exist and converting it to a simple value if it is an array. The " " command will add a new TOS to the named stack, if there is a value it will be pushed to the next on stack. The " " command will read the current top of the named stack, if there isn't one it will return zero and not give an error. The " " command will act like the " " command but instead of copying the TOS it moves it to the main stack and errors if it doesn't exist.

The " " command will ensure the current top of the named stack is an array (creating or converting it if necessary) and then will set the element as requested. The " " operator should only be used against stacks where the TOS is known to be an array. Setting the named stack with " " will discard the array, pushing a new value with " " will hide the current TOS even if it's an array and " " will correctly reveal it again. All other operations with arrays are undefined; copying or moving an array to the main stack is likely to cause the interpreter to crash.

Computational class
There are at least four known, essentially different, proofs that dc is Turing complete:


 * Because dc contains "duplicate", "push string", and "eval" instructions, it embeds the (Turing-complete)  fragment of Underload.
 * The  and   commands provide multiple independent stacks, allowing for a stack-based data storage. (To complete the proof, it's also required to show that a full set of control flow is available, most simply by using the array as a lookup table and implementing StackFlow.)
 * It's also possible to use the array itself as data storage for a Turing-completeness demonstration, e.g. by implementing the I/D machine.
 * Finally, because dc uses bignums, you can implement a Minsky machine more or less directly.

Examples
This prints the numbers from one factorial to 20 factorial in base 11.

[la1+dsa*pla20>y]sy 0sa1 11o lyx

This prints the first 20 Fibonacci numbers:

1d[prdk+KdZ5>x]dsxx