a{a}
Every function is a list of cases, and a text is a function that gives one character code for each place.
2021 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
a{a}, said "a returns a", is from 2021 and is built on recursion. A function is a list of cases. The only data type is the whole number, and the only built-in functions are inc and dec, which add and take 1. Adding, multiplying and even finding the sign of a number are functions you write yourself, and the specification writes them out.
Read the story
Text is a function too. Called with 0 it gives the code of the first character, with 1 the second, and 0 after the last one. The input comes into main as such a function, and when main returns one, its characters are printed.
The machine
| Syntax | Does |
|---|---|
name[a,b]{cases} | Define a function with the inputs a and b |
name{cases} | Define a function without inputs |
x=y>z | A case that returns z when x and y are equal |
z | A case that returns z when no case with = matches |
f(x) | Call f, with exactly as many inputs as it takes |
inc dec | Add 1, take 1 away |
# | A comment to the end of the line |
A run calls main. A number it returns is printed in decimal. A function it returns is called with 0, 1, 2 and so on, and each code is printed as a character until one is 0. A function defined inside another keeps the variables around it, so caseReplacer[f,b,r]{g[a]{a=b>r,f(a)}} returns a text that differs from f in one place.
Example
The cat returns its input, which is already a text.
The cat returns its input, which is already a text. The truth machine compares the first character with the codes of 0 and 1. On 0 it returns a text of one 0, and on 1 a text that is 1 at every place and never ends.
The Hello world spells its text with one case per place.
Its second code is 97, an a, so it says Hallo. The specification also builds addition, the sign of a number, multiplication, Fibonacci and factorial out of inc and dec alone. With those, main{fib(10)} prints 55 and main{factorial(5)} prints 120.
Patterns it teaches
- Lambda encoding: texts and arrays are functions from places to values.
Further
See also
Functional paradigm
Write your own in Run Convert a program from a{a}
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: a-returns-a.
Command line
shib run a-returns-a -e 'main[i]{i}' --input 'Hello, World!'shib manual a-returns-aSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/a-returns-a.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org