esolang

Rational

A program is a single number. Its digits spell combinators, and the part after the point decides how.

Cel7t, 2023 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: ``SKK

The idea

Cel7t made Rational in 2023. A whole program is one rational number, written in hexadecimal for convenience, and it stands for an expression of the S and K combinators with the backquote of Unlambda for application. Every program has endless backquotes on its left, so a list of combinators is applied from left to right. 1A is S K K, which is the identity function.

Read the story

The specification calls the search for the smallest number that does the same as a program its complete evaluation. Among whole numbers, for 1A that number is 19, which is S K S. Such a search need not end.

The machine

Without a fractional part the number is written in base 4, and each digit becomes one symbol.

DigitBecomes
0A backquote
1S
2K
3Nothing

With a fractional part the mapping is made by the program itself. The fraction's base-4 digits are cut at every 0 into sequences, in which 1, 2 and 3 stand for a backquote, S and K. The natural part is then read in chunks of as many bits as it takes to number those sequences. A chunk of 0 is a backquote and a chunk of k is the kth sequence.

In 1A.A3 the fraction is 2203 in base 4, so the sequences are 22 and 3, and chunks of two bits number them. The natural part, 01 10 10, becomes 22 3 3, which is S S K K.

Rational has no output of its own. Like the transpiler, this implementation prints the Unlambda expression the number stands for, with the backquotes it needs in front.

Example

Expected: ```SSKK
Expected: ``SKS

Patterns it teaches

  • Combinators: S and K are all there is.
  • Encoding tricks: the fraction is the program's own code table for the digits before the point.

Further

Functional paradigm

Write your own in Run Convert a program from Rational

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: rational.

Command line

shib run rational -e '1A'
shib manual rational

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/rational.js

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

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