Turnstyle

Turnstyle is a graphical esoteric programming language loosely inspired by Piet. Both encode programs as images, however, the similarities end at the syntax level.

Where Piet is really a stack machine in disguise, Turnstyle is an encoding of the (untyped) Lambda calculus. This allows for building more reusable images at a higher level of abstraction, while still keeping the specification small, making it relatively easy to develop new interpreters.

This repository contains the language specification, a reference implementation in Haskell, and a simple JavaScript implementation.

Specification

The cheatsheet below provides a high-level overview, for more details please consult the Turnstyle Language Specification.

Cheatsheet

Examples

The starting Turnstyle shape is outlined. Click on the examples to run them in the browser.

pi

Prints an approximation of pi by comparing the circle to its diameter:

rev

Uses a Y combinator (indicated by the red rectangle in the top left) and continuation-passing style to implement the Unix rev program. Type lines into the terminal to revert them.

loop

Of course, fixed-point combinators are a primitive tool necessary to compensate for the limitations of one-dimensional programming. In two-dimensional programs, we can implement recursion using a more visually intuitive approach. This program prints the sequence of natural numbers:

Design Principles

In roughly this order:

  1. In the spirit of Lambda calculus, the specification should prioritize simplicity and clarity.
  2. Preserve the suspension of disbelief concerning using this for real programs:
  3. Allow plenty of creative freedom in the choice of colors and shapes.
  4. Represent integers as areas as a nod to Piet (as a side effect, 0 does not exist as a literal).