oris 0.2.1

An interpreter for Monkey
Documentation
  • Coverage
  • 14.29%
    1 out of 7 items documented1 out of 1 items with examples
  • Size
  • Source code size: 95.15 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 4.03 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • bebecue/oris
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • bebecue

crates.io documentation

oris

An interpreter for Monkey

Install

cargo install oris

REPL

$ oris
>> 1 + 1
2
>>

Script

$ cat dt.oris
let answer = 2 * 3 * 7;
print(answer);

$ oris dt.oris
42

Embedded

let code = b"
let is_composite = fn(n) {
    let f = fn(d) {
        if n <= d {
            false
        } else {
            let q = n / d;
            if q * d == n {
                true
            } else {
                f(d + 1)
            }
        }
    }

    f(2)
}

let sum = fn(m) {
    let f = fn(n) {
        if n == m {
            0
        } else {
            if is_composite(n) {
                0
            } else {
                n
            } + f(n + 1)
        }
    };

    f(1)
}

sum(limit)
";

let mut env = oris::Env::builder().with_int("limit", 14).build();

let result = oris::entry(&mut env, code).unwrap();

assert_eq!(result.as_int().unwrap(), 42);