Functionable
Jump to navigation
Jump to search
Functionable is an esolang made by User:PKMN Trainer.
Syntax
Most commands are written as functions
[COMMAND_NAME]([OPERAND1],[OPERAND2],[OPERAND3...])
Labels work like this:
label:nop()
; is a seperator. Newlines assemble into semicolons unless they occur after a comma, and '' assembles into ord(). Spaces can only be used when inside '' or ord()
Non-existent functions are ignored. Built-in functions exist, which are:
| Function | Pseudocode | Notes |
|---|---|---|
| add(a,b) | return a + b | |
| neg(a) | return -a | |
| mul(a,b) | return a * b | |
| recip(a) | return 1/a | |
| gt(a,b) | return a > 0 | |
| eq(a,b) | return a == 0 | |
| jump(a) | jump to line a | |
| input(a) | if a = 0 then return num_input else return char_input_as_num | |
| not(a) | return !a | |
| or(a,b) | return a || b | |
| if(a,b,c) | if a then b else c | Can span multiple lines |
| output(a,b) | output a if b = 0 else output char(a) | If a is a list (example: [65, 66, 67]) then it will be displayed as a string if b = 1 |
| let(a,b) | let a = b | |
| define(a,b0,b1,b2...c) | def a(b0,b1,b2...): c | Variable amount of inputs. Must have at least 3 inputs. Can span multiple lines |
| ord(a) | char_to_ascii(a) | 'a' does the same thing. This function assumes the input is a character and not a variable unless it is preceded by var-
|
| halt() | halt | The only built-in function to have no inputs |
| list(a0,a1,a2...) | [a0, a1, a2...] | Represents a list |
| push(a,b) | a.push(b) | |
| index(a,b) | a[b] | let(index(a,b),c) is a[b]=c in pseudocode
|
| nop() | Useful for if statements since empty operands result in an error. |
"Unofficial" functions (these are not built-in):
| Function | Code (?) | Notes |
|---|---|---|
| repeat(a,b) | line: if(eq(a,0),nop(),b;add(a,-1);jump(line)) | Can be multiline |
| while(a,b) | line: if(a,b;jump(line),nop()) | Can be multiline |
Programs
Cat
Readable version:
let(char,input(1)) if( eq(char,0), halt(), output(char,1) jump(0) )
True version:
let(char,input(1));if(eq(char,0),halt(),output(char,1);jump(0))
Truth-machine
Readable version:
let(a,input(1)) let(b,eq(a,49)) output(a,1) if( eq(a,ord(1)), jump(2), halt() )
True version:
let(a,input(1));let(b,eq(a,49));output(a,1);if(eq(a,ord(1)),jump(2),halt())
Hello world
Readable version:
output(list('H','e','l','l','o',',',' ','w','o','r','l','d','!'),1)
True version:
output(list(72,101,108,108,111,44,32,119,111,115,108,100,33),1)
Factorial
Readable version:
output(list(48,10),1) let(a,1) start:let(c,1) let(b,a) multiply:let(c,mul(c,b)) let(b,add(b,-1)) if(gt(b,1),jump(multiply),nop()) output(c,0) output(10,1) jump(start)
True version:
output(list(48,10),1);let(a,1);let(c,1);let(b,a);let(c,mul(c,b));let(b,add(b,-1));if(gt(b,1),jump(4),nop());output(c,0);output(10,1);jump(2)
Computational class
Functionable is Turing-complete, it can simulate a 2-counter Minsky machine.