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
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
| Bird | Rule |
|---|---|
m mockingbird | m x = x x |
0 kite | 0 x y = y |
w warbler | w x y = x y y |
u Turing bird | u x y = y (x x y) |
o owl | o x y = y (x y) |
t thrush | t x y = y x |
l lark | l x y = x (y y) |
b bluebird | b x y z = x (y z) |
c cardinal | c x y z = x z y |
q queer bird | q x y z = y (x z) |
v vireo | v 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.
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.
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
See also
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-birdSource
- 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