As a stack-based, concatenative and procedural programming language, **dc** programs follow a *bottom up* approach where the program is built by
starting with the most minimal facts about the problem and then is build up towards the complete solution. Following this programming paradigm means
creating many short and simple routines that are defined either in terms or existing routines or in terms of built-in primitives.
The main strength of this paradigm is that you have full control on what happens at the lower levels of your program. This means that your
programming logic is not abstracted away into generic protocols, everything you write has to as concrete as possible.
Another advantage of this approach is the ability to test and debug interactively each definition and each routines as you build up your solution, without having
to rely on external testing framework.
Finally, the last major advantage is that dc is very extensible: the core language consists on only a few primitives, which are enough for building solutions
and extending the programming language. Furthermore, just as LISP languages, dc does not make any distinctions between code and data, thus it is homoiconic.
On the other hand, the *bottom up* approach is not suitable for building large infrastructures: the ability to abstract away methods, procedures and to shape
real-world objects into templates is essential for many modern programming use cases. As a result, dc excels when used for what it was originally
developed for: computations and small math-oriented programs.
within the main stack. The _main stack_ is virtually infinite and grows as much as needed; the _main stack_ is **public**, i.e. it is
shared between any **dc** command.
The **register** is an hash map-like abstract data type that allows users to operate on an _isolated_ environment formed by a _stack_
and an _array_. Each instance of the register is an ordered pair `(key, value)` where the _key_ is a character representing the name of the
register and the _value_ is a **private** instance of a stack and a **private** instance of an array. **dc** commands - exception made for registers, macro and array commands -
Arrays support random access through an index. You can store a value in an array and retrieve it later.
**:**`r`
Will pop the top two values off the stack. The second-to-top value will be stored in
the array `r`, indexed by the top-of-stack value.
**;**`r`
Pops the top-of-stack and uses it as an index into array `r`. The selected value
is then pushed onto the stack.
## 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 content of a string can executed as a _dc_ program). Any kind of 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_ (contained between balanced **\[** and **\]** characters), and pushes it on the stack. For example, **\[ Hello World \] P** prints the string **Hello World** (with no newline).
**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, **\[ 1 p \] x** executes the macro **1 p** which pushes **1** on the stack and prints **1** on a separate line.
Macros are most often stored in register's stacks; **\[ 1 p \] sa** stores a macro to print **1** into register's stack **a**, and **la x** invokes this 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 greater or equal to 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 less or equal to 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.
## Status Inquiry
**Z**
Pops a value off the stack, calculates the number of digits it has (or number of characters, if it is a string) and pushes that number.
**z**
Pushes the current stack depth: the number of objects on the stack before the execution of the **z** command.
## Miscellaneous
**q**
Exit with return code `0`.
**?**
Reads a line from the terminal and executes it. This command allows a macro to request input from the user.
The original version of the **dc** command was written by Robert Morris and Lorinda Cherry.
This version of **dc** is developed by Marco Cetica.
# BUGS
If you encounter any kind of problem, email me at [email@marcocetica.com](mailto:email@marcocetica.com) or open an issue at [https://github.com/ice-bit/dc](https://github.com/ice-bit/dc).