A dynamically-typed, RPN-based, and stack-based esoteric language.
> 'Hello World!'; // Hello World!
> 1 1 + 2 2 + -; // -2
x = 5;
< 1 2 3 $x [>]; // [5, 3, 2, 1]
adder = (a) => (
(b) => $a $b +
);
> 3 5 $adder@@; // 8
is_prime = (num) => (
$num $sqrt@ $floor@ 2 (sqnum, i) => ({
$num $i % 0 == : !?,
$i $sqnum >= : $num 1 !=,
!! : $sqnum $i 1 + $@
})@
);
> 1231 $is_prime@; // true
See the explanation for the language at the documentations.
Note that it is not a guide but rather just the syntax and operators.
RPNLang is interpreted with JavaScript.
You can require the module and run code:
const RPNProgram = require('rpnlang');
const program = new RPNProgram('> 1 1 +;');
program.execute(); // 2
You can also use RPNProgram.makeModule
in order to make a module compatible with RPNLang.
To call a lambda from RPNLang, use RPNProgram.callLambda
.
const RPNProgram = require('rpnlang');
module.exports = RPNProgram.makeModule({
num: 5,
add: (a, b) => a + b,
map: (...args) => {
const mapper = args[0];
return args.slice(1).map(e => RPNProgram.callLambda(mapper, [e])[0]);
}
});
math << 'math.js';
> math::num 10 math::add@; // 15
source
- The source code.options.log
- Function for standard output.options.debug
- Debug mode, prints more errors.options.safe
- Disables file I/O and stdin.
You can also run a file via the CLI:
$ rpn input_file.rpn
-c [code]
- Runs code.-d
- Enables debug mode.-s
- Enables safe mode.
RPNLang is made purely for fun, don't take it too seriously!
Created with jison.