SKR
Combinatory logic with a third combinator that can look inside an expression without running it.
Hakerh400, 2024 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
Hakerh400 made SKR in 2024. It keeps K and S from combinatory logic and adds R. In plain combinatory logic a program can only apply what it is given. R lets it ask whether the thing is a bare combinator or an application of one expression to another. With that, a program can take any expression apart and count, compare or rebuild it.
The machine
| Rule | Result |
|---|---|
K x y | x |
S x y z | x z (y z) |
R x K, R x S, R x R | x K |
R x (y z) | x S y z |
R first works its second argument down to weak head normal form, so y z is one of K x, R x, S x or S x y. A program is a list of definitions name = expression, each using only the ones before it. The last one is the main function. It is applied to the input, and its result is the output, printed as a normal form. a # b # c d is short for a (b (c d)).
Example
R I turns an application f a into S f a and a bare combinator into K.
R I turns an application f a into S f a and a bare combinator into K. The input K K R is reduced to K before R looks at it.
The specification builds booleans, pairs, binary numbers, lists and an equality test out of these three, 158 definitions in all. Its last program names the combinator that appears most often in the input. On the input S (S (R # K R) # S R # S S) # R # K # K # K # K # R R it prints R in 115,846 steps.
Patterns it teaches
- Combinators: K and S are the classic basis.
- Code as data: R reads an expression the way a parser would.
Further
See also
Functional paradigm
Write your own in Run Convert a program from SKR
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: skr.
Command line
shib run skr program.txt --input 'S (S (R # K R) # S R # S S) # R # K # K # K # K # R R'The program is long; save it as program.txt first.
shib manual skrSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/skr.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org