esolang

SKM Calculus

SKI calculus with a guard. M lets a value through only once it has become K or S.

Hakerh400, 2022 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: K (K K K)

The idea

Hakerh400 made SKM Calculus in 2022. It keeps the K and S of SKI calculus and adds M, which SKI cannot build. In SKI a function can be handed any expression and has to hope it does something meaningful. In SKM a program can use K and S as two constants and match on them. M x goes on only once x has reduced to K or S. Anything else leaves it stuck, which the specification compares to bottom in Haskell.

Read the story

Reduction is stricter than in SKI. Only the head of an expression reduces, and an argument never reduces before its function, except the argument of M. So there is only one way to reduce any expression.

The machine

ExpressionReduces to
K a ba
S a b ca c (b c)
M aa, once a has reduced to K or S

Application is left-associative, so a b c is (a b) c. The output is the expression the program reduces to, written the way the specification writes them.

Example

K (K K K) stays as it is, because only its argument could reduce.
Expected: K
Expected: M
Expected: M (K K) S

K (K K K) stays as it is, because only its argument could reduce. Behind M the same argument does reduce, first to M K and then to K. S K K is the identity, as in SKI. K K K K stops at K K, which is neither K nor S, so the M in front of it never lets go. The specification does not say how such a stuck M is shown; it keeps its argument as far as that went.

Patterns it teaches

  • Combinators: K and S as in SKI, and M to tell them apart safely.

Further

Functional paradigm

Write your own in Run Convert a program from SKM Calculus

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run skm-calculus -e 'K K K'
shib manual skm-calculus

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/skm-calculus.js

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

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