Gs2

gs2 is a a concatenative language designed by User:nooodl, inspired by GolfScript and J, designed to be as efficient as possible at code golf. gs2 code uses a binary format in which most bytes represent a single high-level stack operation. The code is run over stdin token by token, just like GolfScript.

The documentation that used to be here is mostly out of date now, and until the author gets around to writing up something more thorough, careful reading of the source code is your best bet, as with FlogScript. An old revision can be found here:

<!--

Syntax
Code is tokenized as follows:

# string hack: programs can omit starting \x04 and save a byte if re.match('^[^\x04]*[\x05\x06]', prog): prog = '\x04' + prog token_re = [ '\x01.',                     # unsigned byte '\x02..',                    # signed short '\x03....',                  # signed long '\x04[^\x05\x06]*[\x05\x06]', # string (array) '\x07.',                     # 1 char string '.',                         # regular token ]   tokens = re.findall('|'.join(token_re), prog, re.DOTALL)

Tokens starting with \x01 through \x03 push little-endian binary integers to the stack. Sequences of strings are delimited by \x04 and \x05, and split by \x07. The final \x05 byte can be replaced by \x06 in which case the strings are wrapped in an array. Some examples:

04 'a' 'b' 'c' 05                  => "abc" 04 'a' 'b' 'c' 07 'd' 'e' 'f' 05   => "abc" "def" 04 'a' 'b' 'c' 06                  => ["abc"] 04 'a' 'b' 'c' 07 'd' 'e' 'f' 06   => ["abc" "def"]

The following tokens are all "special" syntactically, i.e. not just a stack operation:


 * \x08 opens a block, \x09</tt> closes it. (These function like GolfScript's curly braces.) The mnemonics are {</tt> and }</tt>.


 * \x4d __</tt> pushes a 1-byte block. Mnemonic: '</tt> (as in a Lisp quote.)


 * \x4e __</tt> maps a 1-byte block over the top of the stack. Mnemonic: m</tt>.


 * \x4f __</tt> filters a 1-byte block over the top of the stack. Mnemonic: f</tt>.


 * \x5c __</tt> maps a 2-byte block over the top of the stack. Mnemonic: mm</tt>.


 * \x5d __</tt> filters a 2-byte block over the top of the stack. Mnemonic: ff</tt>.


 * \x5e</tt> opens a map block that lasts until the end of the program (or the next }</tt>). Mnemonic: m:</tt>.


 * <tt>\x5f</tt> opens a filter block that lasts until the end of the program (or the next <tt>}</tt>). Mnemonic: <tt>f:</tt>.

Commands
In the "from" and "to" columns, following variables are used:
 * &alpha;, &beta;, &gamma; represent any stack value, &kappa; represents a constant
 * f, g, h represent blocks
 * a through z otherwise represent integers
 * [&alpha;], [&beta;] represent lists.

Examples
(TODO) -->

External resources

 * github repo