2L

From Esolang
Jump to: navigation, search

2L (the Two Language), designed by Gregor Richards, is an esoteric programming language derived loosely from the PATH programming language and Brainfuck. 2L is Turing Complete.

Like PATH and Befunge, it's two-dimensional. Like Brainfuck, it operates on a tape. However, it only has two symbols. It manages this by overloading the * symbol by direction. The data pointer starts at the third cell of the tape, not the first as in Brainfuck, because the first and second cells (called TL0 and TL1) are used for I/O. The tape is initially filled with 0s, as in Brainfuck. The program pointer starts at the upper left corner (0,0) moving down, and ends when the program pointer goes over either the left or top edge (i.e. when either its x or y coordinate goes below 0.)

The action is undefined when the pointer goes over the right or bottom edge, as the board is considered to expand infinitely in both directions. Exiting, erroring, segfaulting and looping infinitely are all appropriate results.

Symbols

Symbol Function
*

All IO and tape operations. This operation has a different function for all four cardinal directions:

  • Up: Move the data pointer to the right (> in Brainfuck)
  • Down: Move the data pointer to the left (< in Brainfuck)
  • Left: Decrement the value at the data pointer (- in Brainfuck)
  • Right: Increment the value at the data pointer (+ in Brainfuck)

In Gregor's implementation, the actions going up and down were inadvertently reversed.

+

If the value the data pointer points to is nonzero, turn right, otherwise turn left

The + actually acts sort of like a turning wall. Rather than turning like so:

   ^
>>>+

You turn like so:

  ^
>>/+

All other symbols do nothing, but since they do affect the layout, they are not completely ignored. Therefore, 2L actually has three instructions, the third being "nop." Without this, 2L would be of very little computational usefulness.

I/O

The two leftmost tape locations, called TL0 (Tape Location 0) and TL1 (Tape Location 1) respectively, are significant. TL1 doesn't actually hold a value, it merely causes an I/O operation if you attempt to increment or decrement it. If the value at TL0 is 0, and you attempt to change the value of TL1, a character will be read from input into TL0. If TL0 is not 0, and you attempt to change the value of TL1, a character will be outputted from the value of TL0.

Example

Because of the extreme level of overloading, even the simplest program is incredibly complex in 2L. It becomes difficult to produce an arbitrary effect at an arbitrary point, because you have to be travelling in the right direction first.

Here's a simple loop, which produces the value 9 by multiplying 5 by 2 then subtracting 1:

 **  +
+  +               
   * *****+
  +
    +    *
  +     * 
         +
  *       +
   +

This example is just a small sample of a program.

A larger more complex example, a Hello, World! program:

 *+ 2L "Hello, World!" program by poiuy_qwert   +
+                                                   +
 *                                             +*
 *     +                                        *+
    + **                                     +    *
      +*                                           +
     *  +                                                               *+
     +                                        +                         *
   +******************************************* *************************
                                                 +                      +
                                                     +
                                                 *+
    +                                          *+*
      +                                        *+  *
     *                                          +  *+
     +                                           + *  +
   +********                                       *      +
                                                   + +*
    +                                             *   *+
      +                                           *+    *
     *                                             +    *+
     +                                              +   *    +
   +******                                              **+
                                                        +*
                                                        +  *
                                                           *+ +
    +                                                *   +        +
     ***+                                            *     * +*
   +                                                       *  *+
       *                                              +    +    *
    +  +                                                  *   *+ +
     ************************+                            * + * +
   +                                                          *     +
                            *                              +  + *+
                            +                                  +*
                                                              +   *
    +                                                        *  *  +
     *******************************************************+* +  *   +
   +                                                              *       +
                                                           *  +   +  +*
    +                                                      +     *    *+
      +                                                          *+     *
     *                                                            + *    +
     +                                                             + *  *
   +************                                                        *    +
     +                                                               *  +         +
    *                                                                 +      * +
    +                                                                  *+   +** 
  +******************************************************************* *
                                                                       +   +    *       +
                                                                             *   +         +
   +                                                                        +          +*
    ***+                                                              *         *       *+
  +                                                                             * 
                                                                      *         +   +    *    +
      *                                                                +              *   +        +
   +  +                                                                              +        *+
    *******+                                                                   *         *   +*
  +                                                                                      *
                                                                               *         +  +    *
          *                                                                     +             *   +
   +      +                                                                                  +
    *****************************+                                                     *         *
  +                                                                                              *
                                                                                       *         +
                                *                                                       +
                                +
  ************************************************************************+                    *
 +                                                                       *                     *
                                                                                                +
                                                                         +

See also

  • 1L describes several proposals for reducing 2L from three symbols to two.
  • 2-ill is a language "something like 2L but a bit different".

External resources