normalcalc
S and K, evaluated lazily, with the I/O of a Haskell program. A byte is a Church numeral.
Itoh Shimon, 2024 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
Itoh Shimon designed normalcalc on 25 and 26 November 2023 and published it on 31 July 2024. It comes from Unlambda and Lazy K. A program is a tree of applications, written with a backtick in front, of a handful of one-character combinators. Two of them are S and K, which are enough for any computation. The other four build procedures the way Haskell's IO monad does. The whole program is one procedure, and running it is what reads and prints.
Read the story
Evaluation is lazy, so fixed point combinators work, and a byte is a Church numeral, the function that applies its argument n times.
The machine
A backtick applies what follows it to what follows that, so `ab is a applied to b.
| Char | Name | Takes and gives |
|---|---|---|
* | S | x, y and z, gives x z applied to y z |
/ | K | x and y, gives x |
_ | return | x, gives a procedure whose value is x |
| | bind | a procedure m and a function f, gives a procedure that runs m and then f on its value |
, | input | any value, which it drops, gives a procedure that reads a byte |
. | output | a byte, gives a procedure that prints it and whose value is the identity |
# starts a comment, and every other character is ignored. As in the Haskell in the specification, the end of input reads as 256, and a printed number is taken modulo 256.
Example
The no-op returns K and prints nothing.
The no-op returns K and prints nothing. Its cat binds the input procedure to the output function, so it copies one character.
Printing a fixed byte needs its numeral. The identity S K K, written ``*// , is also the numeral 1, and the successor S (S (K S) K) is `*``*`/*/ , so applying it to 1 gives 2 and once more 3. A numeral applied to another raises that one to its power. 2 applied to 2 is 4, and 4 applied to 3 is 81, the letter Q.
Patterns it teaches
- Combinators: S and K, as in Unlambda.
- Lambda encoding: bytes are Church numerals, and the empty tuple is the identity.
- Turing tarpit: two combinators compute, four more talk to the world.
Further
See also
Functional paradigm
Write your own in Run Convert a program from normalcalc
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: normalcalc.
Command line
shib run normalcalc -e '`_/'shib manual normalcalcSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/normalcalc.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org