esolang

Lazy Bird

Unlambda with the whole aviary of To Mock a Mockingbird, and lambdas you may write by hand.

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

Tested with 3 known programs · Test method

Run it

Expected: hello, world!

The idea

Slereah made Lazy Bird in 2008. It starts from Unlambda, with ` to apply, s, k and i, and .x to print, and adds the birds of the puzzle book To Mock a Mockingbird. The mockingbird m applies its argument to itself, the thrush t swaps two, the bluebird b composes. Each bird could be written in s, k and i, and the specification gives that form for every one.

Read the story

A program may also hold lambdas. ^m^n^f^x``mf``nfx is addition on Church numerals. Before the run every lambda becomes s, k and i, and then the expression is rewritten, leftmost application first, until no application is left.

The machine

BirdRule
m mockingbirdm x = x x
0 kite0 x y = y
w warblerw x y = x y y
u Turing birdu x y = y (x x y)
o owlo x y = y (x y)
t thrusht x y = y x
l larkl x y = x (y y)
b bluebirdb x y z = x (y z)
c cardinalc x y z = x z y
q queer birdq x y z = y (x z)
v vireov x y z = z x y

@ is Iota's combinator, x s k. # swallows every argument, as Unlambda's v does. & compares its two arguments as written and gives k or 0, which are true and false. .c prints c and r a line feed, and a, n, p and x never reduce. The input command _ is left out; the specification itself says it is hard to run at the right moment.

Example

Hello world is a chain of printers.

Hello world is a chain of printers. Each .c prints its letter and hands the next one along.

2 + 5 in Church numerals. The specification says it prints seven *, but the printer in it is .x, so it prints seven x.

Expected: xxxxxxx

The countdown takes a Church numeral at its end. With 3, written ``sb``sbi , it prints three x, then two, then one, a line each, and stops at 0.

Expected: xxx xx x

The Fibonacci program prints the sequence in unary, one number a line, from 0, and never stops.

Patterns it teaches

  • Combinators: a dozen named birds, each one a shorthand for s and k.
  • Lambda encoding: numbers are Church numerals, true and false are k and 0.

Further

Functional paradigm

Self-modifying

Write your own in Run Convert a program from Lazy Bird

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run lazy-bird -e '`````````````.h.e.l.l.o.,. .w.o.r.l.d.!i'
shib manual lazy-bird

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/lazy-bird.js

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

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