Pure BF

From Esolang
Revision as of 06:22, 19 January 2012 by Zzo38 (talk | contribs)
Jump to navigation Jump to search

Pure BF is a completely functional joke programming language based on brainfuck.

Details

Every first class value is a function of the type

   (Tape, World) -> (Tape, World)

A program technically doesn't have to be run after being compiled, as the language is purely functional, but the interpreter/compiler is encouraged to create an infinite tape, pair it with the world and apply the program to it, as that will make it possible to inspect the results of the code.

Commands

Pure BF only has two commands:

   ab  -- composes the functions a and b in the reverse of normal composition order.
   [a] -- creates the function that works like the identity function if the current cell is
          zero, and works like a[a] if it isn't.  Equivalently, creates a function that
          returns its input unchanged if  the cell under the tape head is 0, otherwise returns
          [a] applied to a applied to its input.

Built-in functions

Pure BF has 6 built-in functions that aren't the identity function:

   > -- copies the input tape, but with the head moved a single cell forwards.
   < -- copies the input tape, but with the head moved a single cell backwards.
   + -- copies the input tape, but with the current cell being 1 higher.
   - -- copies the input tape, but with the current cell being 1 lower.
   . -- copies the world, but with the output containing the value of the current cell.
   , -- copies the world and the input tape, but with one character moved from the input stream to
        the current cell.

Any other character is the identity function.

Computational Class

Pure BF is trivially equivalent to brainfuck. Here is a cross-language program (written in Pure BF and brainfuck) which converts one language to the other:

   ,[.,]