esolang

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.

CharNameTakes and gives
*Sx, y and z, gives x z applied to y z
/Kx and y, gives x
_returnx, gives a procedure whose value is x
|binda procedure m and a function f, gives a procedure that runs m and then f on its value
,inputany value, which it drops, gives a procedure that reads a byte
.outputa 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.

Expected: A
Expected: h

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.

Expected: Q

Patterns it teaches

Further

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 normalcalc

Source

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