a returns a

From Esolang
Jump to navigation Jump to search
The title of this article is incorrect because of technical limitations. The correct title is a{a}.

a{a} (pronounced a returns a) is an esolang that is based on recursion. A function is just a list of cases, and can be defined by itself or inside another function. Functions can also have other functions as inputs and return values. There are no built in ways to do most mathematical functions, and you must instead call a function that does that action. The only inbuilt data type is integers, however functions are easily turned into array like objects.


Function declaration:

Syntax Description
name The first part is the name of the function, which starts with any letter, and then is any letter/number or _
[a,b,c...] the second part is a list of variable names. this can be any length, include the same characters as function names, and is optional.
{a=b>c,d} the last part is a list of cases. a, b, and c can be any number, variable, function, or function definition and can be called. the first case in this example checks to see if a and b are the same, and if the are, returns c. If a case is just a number or variable, then that is returned if no other cases are matched, like d in this example.



Functions can also be defined inside of another function. The declaration can use variables from the parent function, which are hardcoded into the new function.

A function is called by adding parenthesis to the end, which can also happen right after a function declaration. The number of inputs a function is supplied with must be equal to the number of inputs it was declared with. The program starts by calling the function named main, and if the main function is defined with inputs, then it asks for those inputs before running.

There are only 2 inbuilt functions, inc and dec. inc returns the input + 1. dec returns the input - 1.

When a program is ran, main is called first. main is only allowed one input. If main has an input, then the user is asked for the input. if it does not, then it is just ran normally.

Whitespace is ignored, so you can format your program however you want. You can also comment with # until end of line.


Input and output is handled with a function that acts like an array. The function is defined with an input starting at 0 which returns the first character of the string represented in ascii, then 1 which returns the second and so on, until its ended with a 0. The input is converted into a function, and is passed to main. Output is handled after the main function returns a value. If it's an integer then that integer is printed. If it's a function, it prints the ascii of that function called with 0, then called with a 1, and so on until it gets a value of 0.

Code examples

Hello world:

str[i]{i=0>72, i=1>97, i=2>108, i=3>108, i=4>111, i=5>32, i=6>87, i=7>111, i=8>114, i=9>108, i=10>100, i=11>33,0}



Truth Machine:


Function wrapper:


Replacing a case in a function(can be used to edit arrays):


Useful misc functions:

choose[a,b,c]{c=-1>a,c=1>b} #chooses between a and b
sign[n]{n=0>0,sign2(n,n)} # gives the sign of a num 
addSign[n,c]{c=0>n,c=1>inc(n),c=-1>dec(n)} #takes a num and a sign and returns the addition
invert[n]{n=0>0,n=1>-1,n=-1>1,invert2(n,0)} #inverts a number
add[a,b]{b=0>a,add(addSign(a,sign(b)),addSign(b,invert(sign(b))))} #addition
mulSign[a,b]{a=-1>invert(b),a=1>b} #finds what the sign of a multiplication should be  
posMul[a,b,total]{b=0>total,posMul(a,dec(b),add(a,total))} #finds the result of a multiplication between two positive numbers 
mul[a,b]{a=0>0,b=0>0,mulSign(sign(a),sign(b))=-1>invert(posMul(abs(a),abs(b),0)),posMul(abs(a),abs(b),0)} #multiplication, including negatives 
fib[n]{n=0>0,n=1>1,add(fib(dec(n)),fib(dec(dec(n))))} #returns nth term of the fibonacci sequence 
factorial[n]{n=1>1,mul(n,factorial(dec(n)))} #returns n!