brainFn
- This article is not detailed enough and needs to be expanded. Please help us by adding some more information.
- This is still a work in progress. It may be changed in the future.
Paradigm(s) | functional |
---|---|
Designed by | User:Nurdle |
Appeared in | 2023 |
Memory system | Cell-based |
Dimensions | one-dimensional |
Computational class | Turing complete |
Major implementations | Canonical |
Influenced by | Brainfuck, Brainfunc, Brainfunct |
Influenced | Unknown |
File extension(s) | .bfn |
brainFn (short for brainFunction) is a functional brainfuck derivative inspired by Brainfunct made by User:Nurdle in 2023, that builds upon brainfuck by adding labels and function concatenation.
Language Overview
brainFn is a superset of brainfuck, which means that all valid brainfuck is valid brainFn (given that the comments don't use any newly reserved symbols).
Command | Description |
---|---|
= |
set pointer value to 0 |
+ |
increment pointer value |
- |
decrement pointer value |
@ |
set pointer position to 0 |
> |
move pointer to the right |
< |
move pointer to the left |
. |
print pointer's value to the terminal |
, |
get user input |
[ |
open while loop |
] |
close while loop (loops until pointer value is 0) |
' |
label |
{ |
declare function |
} |
return (can be used outside of functions though it's not recemented) |
; |
call a function |
$ |
push pointer's value to the argument stack |
& |
push pointer's value to the return stack |
% |
pop pointer's value from the argument stack |
: |
pop pointer's value from the return stack |
( |
concatenate functions together |
) |
end function concatenation |
/- |
open comment (optional) |
-/ |
end comment (optional) |
~ |
call another brainFn script |
local functions can be referenced by putting :
at the start of their name, local functions cannot be accessed by other functions, even if you call another function.
Labels
Labels are an essential part of brainFn, standard labels are unbounded in length, however the Canonical Interpreter limits their length to 32 characters. Labels are usually restricted to alpha-numeric characters and underscores, however any label name that starts with :
is valid, as it marks a label as local.
Local Labels
In brainFn, local labels are labels that can only be called in the function they were declared in, for example:
':local' { ... } 'myFunc' { ':local'; } 'myFunc';
the code above won't work, however:
':local' { ... } ':local';
and
'myFunc' { ':local' { ... } ':local' } 'myFunc';
both will work, and
'myFunc' { ':local' { ... } } ':local';
will not work.
Examples
Print Function
'print' { print function, returns the amount of letters printed [%.>+<] >& }
Println Function (using concatenation)
'print' { print function returns the amount of letters printed [%.>+<] >& } 'println' ('print' { +++++ +++++ . print ascii code 10 which is a line break %& return the return value of print })
Variables using Functions and Concatenation
brainFn allows the redefinition of labels, which means you can technically implement variables using functions and concatenation.
'a' { our variable +++ +++ value is 6 & return its value } 'dec' { function that decreases the value of the input and takes 1 away $-& } 'a' ('a' 'dec') take 1 away from our variable
Computational Class
Due to brainfuck being Turing Complete and brainFn being a superset of brainfuck, it can be assumed that brainFn is also Turing Complete.
See Also
- Brainfuck
- Brainfunct - another functional brainfuck derivative.