Clone or download

  • Download the latest version as a ZIP or tarball
  • Clone with: git clone https://elmord.org/code/hatter


The world's first hat-oriented programming language

Hatter is an esoteric programming language. It inaugurates the novel paradigm of hat-oriented programming, in which all computation is represented as taking and dropping data from/into hats. Hats are entities consisting of an argument stack and descriptions of data movements (called magic) to be executed when data is taken or dropped from/into it. Hats can also have other stacks for internal use. Data is generally moved, not copied. A hat can be called recursively, but all instances of a hat share the same argument and internal stacks.

Here is an example hat. It computes the factorial of a non-negative integer (the only data type in the language) using the classical recursive algorithm:

hat fac:
  in @->[[horn->@1]->pred]->[[if<-\fac]<-\nop]->[apply<-pred]->[mul<-@1]->@
  out @->[horn->if]->[if<-1]->@

This code describes a hat called fac, with associated inmagic (run when data is dropped into the hat) and outmagic (run when data is taken from the hat). @ represents the argument stack; @1 is an internal stack. <- and -> move data between hats. Multiple movement operations can be strung together into a movement stream; however, each magic must consist of only one movement stream.

Hatter has no control structures. It does have an if hat, but it behaves like a function (the arguments are evaluated). Conditional execution is achieved through if and apply, which provides the ability of dynamically selecting a hat to move data from/into. \ is a compile-time operator to take the hatid of a hat, a handler that can be fed to apply to make it behave like the corresponding hat.

For more information, see below.