https://github.com/1computer1/rpnlang
An esolang based on RPN
https://github.com/1computer1/rpnlang
esoteric-language rpn stack-based
Last synced: about 2 months ago
JSON representation
An esolang based on RPN
- Host: GitHub
- URL: https://github.com/1computer1/rpnlang
- Owner: 1Computer1
- License: mit
- Created: 2017-07-18T00:11:36.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-08-01T03:04:25.000Z (almost 8 years ago)
- Last Synced: 2025-02-17T21:14:07.298Z (3 months ago)
- Topics: esoteric-language, rpn, stack-based
- Language: JavaScript
- Size: 85.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RPNLang
A dynamically-typed, RPN-based, and stack-based esoteric language.
```
> 'Hello World!'; // Hello World!
> 1 1 + 2 2 + -; // -2x = 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
```## Language
See the explanation for the language at the [documentations](./docs/README.md).
Note that it is not a guide but rather just the syntax and operators.## API
RPNLang is interpreted with JavaScript.
You can require the module and run code:```js
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`.```js
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
```#### `RPNProgram(source[, options])`
- `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.## CLI
You can also run a file via the CLI:
```
$ rpn input_file.rpn
```#### `Flags`
- `-c [code]` - Runs code.
- `-d` - Enables debug mode.
- `-s` - Enables safe mode.## Other
RPNLang is made purely for fun, don't take it too seriously!
Created with [jison](http://zaa.ch/jison/).