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



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

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