Spoon

From Esolang
Jump to navigation Jump to search

Spoon is a Brainfuck derivative invented by S. Goodwin in 1998. It uses Huffman-coded binary sequences to represent each instruction.

Command set

Spoon's command set consists of the commands in Brainfuck, converted to binary sequences through Huffman coding, with two additional commands added on.

Command Description
1 Increment the memory cell under the pointer
000 Decrement the memory cell under the pointer
010 Move the pointer to the right
011 Move the pointer to the left
0011 Jump back to the matching 00100
00100 Jump past the matching 0011 if the cell under the pointer is zero
001010 Output the character signified by the cell at the pointer
0010110 Input a character and store it at the cell in the pointer
00101110 Output the entire memory array
00101111 Immediately terminate program execution

The language allows other characters to be substituted for 0 and 1, or even for 0 and 1 to be swapped, provided the interpreter is informed. It is therefore possible to make Spoon programs that are also ASCII art.

Hello world example

0101111111110010001111111111010000001101100101001011111110010001111110
1000000110111001010111111100101000101011100101001011111111111001000110
0000000000000000001000000110110000010100000000000000000000000000000000
0000000101001011111111111001000111111101000000110110010100101111110010
0011111101000000110110010101110010100000000000000000000010100000000000
0000000000000000101001011111111111001000110000000000000000000100000011
011000001010

Interpreter

As this is a trivial brainfuck substitution an interpreter can be equally trivial.

#!/usr/bin/ruby
h = {
    '1' => 'm[p]+=1;',
    '000' => 'm[p]-=1;',
    '010' => 'p+=1;',
    '011' => 'p-=1;',
    '0011' => ')while((m[p]&=255)!=0);',
    '00100' => '(',
    '001010' => 'putc m[p];',
    '0010110' => 'm[p]=STDIN.getbyte if !STDIN.eof;',
    '00101110' => 'print "\n",m,"\n";',
    '00101111' => 'exit;'
}

r = Regexp.union(Regexp.union(h.keys.sort{|a,b|b.length<=>a.length}),/./);
eval 'm=Hash.new(p=0);'+ARGF.read.gsub(/[^01]/,).gsub(r,h);

External resources

See also