GolfScript

GolfScript is a concatenative programming language embedded on top of Ruby, designed to allow very short programs to be written, in order to win code-golf contests. It supports a range of datatypes including arbitrary precision integers, and a wider range of standard operations than many other esoteric programming languages.

Overview
A Golfscript program is a list of items: integers, lists, strings, blocks, variables, and variable assignments. Integers, when encountered, are simply pushed onto the stack. Lists, strings, and blocks behave similarly. Variables are also pushed onto the stack, except when the variable contains a block. If that happens, the block is executed. When a variable assignment is encountered, the top item on the stack is assigned to the variable, but not popped off the stack.

Syntax and Execution
Lists and blocks are delimited by square brackets and curly brackets, respectively. A block is actually just a string that has special behavior. Variable assignment is done by placing a colon before the variable name. Comments begin with a hash and end at the end of the line. Strings are first evaluated by Ruby, allowing an escape to Ruby expressions and frameworks for those functions not provided by GolfScript, such as floating point and math libraries.

Input and Output
Before a GolfScript program is executed, the input is pushed onto the stack as one long string, and therefore interactive input is impossible. When the program finishes execution, the stack's contents are printed, (apparently) starting from the bottom. There are also some explicit built-in methods of printing.

Built-ins
Most of the golfing power of GolfScript comes from its extensive library of operators. These are actually just variables specially initialized. You can assign values to them if you want. Also, most of the operators are overloaded to provide different results if supplied with different arguments. For example, the asterisk * can mean any of:
 * Multiplication, when supplied with two integers
 * To execute a block a number of times, when supplied with an integer and a block
 * To repeat a string or list a number of times, when supplied with an integer and a string/list
 * To join the elements of a string/list together with another string/list, when supplied with two string/lists
 * To reduce the elements of a string/list to one element, when supplied with a string/list and a block

Coercion
When needed, integers are coerced to arrays/strings/blocks, arrays are coerced to strings/blocks (each element is converted to a string and the results are concatenated together), and strings are coerced to blocks.

List of built-ins
Here is a list of built-ins (currently incomplete), in roughly increasing order of complexity. The arguments describe what types of objects should be on the stack, written bottom to top. A slash means that the arguments are interchangeable. 'List' means arrays or strings; 'sequence' means lists or blocks. This terminology is largely arbitrary.

Examples
99 bottles of beer (considerably golfed) [296,{3/)}%-1%["No more"]+[" bottles":b]294*[b-1<]2*+[b]+[" of beer on the wall\n".8<"\nTake one down, pass it around\n"+1$n+]99*]zip

Quines: Note that since the stack is output at termination, a program like 5 is a quine (as long as no input is given to it). A more non-cheating example could be {".~"}.~ How it works: block {".~"} pushes the .~ string when evaluated. It's duplicated (blocks are printed with parentheses) and evaluated.

Random example of the golfing that can be done with this code: ~{..{(h{3^3%}%2,@h{2\-}%\;++}{,}if}:h~2/zip{{"ACB"=}%}%n*\;

Computational class
GolfScript is Turing-complete, as it can be shown to be computationally equivalent to Underload: the GolfScript built-ins  correspond to the TC subset of Underload commands.

External resources

 * GolfScript homepage
 * Examples of golfscript programs submitted with the intent of minimizing program length. (Scroll down to 'right time' or lower for ones you can view.)