Command-Line Interface¶
RERUM includes a CLI for interactive use and scripting.
Modes¶
REPL Mode¶
Start an interactive session:
Script Mode¶
Run a .rerum script:
Scripts support shebang:
Expression Mode¶
Evaluate a single expression:
Pipe Mode¶
Process stdin:
$ echo "(+ x 0)" | rerum -r rules.rules -p full -q
x
$ cat expressions.txt | rerum -r rules.rules -q
Command-Line Options¶
rerum [script] Run script or start REPL
Options:
-r, --rules FILE Load rules from file (repeatable)
-e, --expr EXPR Evaluate single expression
-p, --prelude NAME Set prelude
-t, --trace Enable tracing
-s, --strategy NAME Set strategy
-q, --quiet Suppress non-essential output
--version Show version
-h, --help Show help
Prelude Options¶
| Name | Description |
|---|---|
none |
No computation (default) |
arithmetic |
+, -, *, /, ^ |
math |
Arithmetic + trig/exp/log |
full |
Arithmetic + predicates |
path.py |
Load custom prelude |
Strategy Options¶
| Name | Description |
|---|---|
exhaustive |
Repeat until fixpoint (default) |
once |
Apply at most one rule |
bottomup |
Children before parent |
topdown |
Parent before children |
REPL Commands¶
| Command | Description |
|---|---|
:help |
Show help |
:load FILE |
Load rules from file |
:rules |
List loaded rules |
:clear |
Clear all rules |
:prelude NAME |
Set prelude |
:trace on/off |
Toggle tracing |
:strategy NAME |
Set strategy |
:groups |
Show all groups |
:enable GROUP |
Enable a group |
:disable GROUP |
Disable a group |
:quit |
Exit |
Script Format¶
Scripts can contain:
- Comments: Lines starting with
# - Directives: Lines starting with
: - Rules: Lines containing
=> - Groups: Lines like
[groupname] - Expressions: Everything else (printed to stdout)
#!/usr/bin/env rerum
# My script
:prelude full
:load base.rules
[local]
@custom: (f ?x) => (g :x)
# Evaluate these expressions
(+ 1 2)
(f a)
Custom Preludes¶
Create a Python file with a PRELUDE dict:
# my_prelude.py
from rerum import binary_only, unary_only
import math
PRELUDE = {
"gcd": binary_only(math.gcd),
"factorial": unary_only(math.factorial),
"even?": unary_only(lambda x: x % 2 == 0),
}
Use it:
Or in scripts: