esolang

Universal Lambda

One lambda term written in bits. It is applied to the input, and what it returns is the output.

flagitious, 2008 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: hello

The idea

flagitious made Universal Lambda in 2008 from binary lambda calculus, to make it fit for code golf. As in Lazy K, the whole program is a single term. It is applied to the input, a list of bytes, and the result is the output, a list of bytes in the same form.

Read the story

A byte is a Church numeral, the function that applies f to x that many times. A list is built from pairs. cons = λa.λb.λx.x a b holds a byte and the rest of the list, and nil = λa.λb.b ends it. So the input hi is cons 104 (cons 105 nil). Binary lambda calculus reads its input as single bits; this implementation reads a whole byte as one item.

The machine

BitsTerm
00 Mλ M
01 M NM applied to N
n ones, then 0The variable of the nth λ out

The program's bytes are read as bits, most significant first. The bits after the first whole term are ignored, so the last byte can be padded any way. Evaluation is lazy, and the output is printed as the list is taken apart.

Example

The identity λx.x is 0010.

The identity λx.x is 0010. Padded to a byte it is 00100000, a space, or 00100001, an exclamation mark. Either is a cat.

The specification says every byte from space to ? is a cat. By the bits that holds up to /. From 0 on, a byte starts 0011, a λ and then a variable of at least 2, with only one λ for it to point at.

The second program drops the first byte. It is cdr, λp.p(λa.λb.b), which applies the list to false. In bits that is 00011000 00100000, and the first byte is a control character. Put behind the identity, with false written λa.λb.(λx.x) b, the same function takes 24 bits that are three printable bytes.

Expected: ello

Patterns it teaches

Further

Functional paradigm

Write your own in Run Convert a program from Universal Lambda

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: universal-lambda.

Command line

shib run universal-lambda -e ' ' --input 'hello'
shib manual universal-lambda

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/universal-lambda.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org