Crates.io | oris |
lib.rs | oris |
version | 0.2.1 |
source | src |
created_at | 2023-02-11 05:44:36.742423 |
updated_at | 2023-03-21 08:42:55.079445 |
description | An interpreter for Monkey |
homepage | |
repository | https://github.com/bebecue/oris |
max_upload_size | |
id | 782356 |
size | 95,618 |
oris
An interpreter for Monkey
cargo install oris
$ oris
>> 1 + 1
2
>>
$ cat dt.oris
let answer = 2 * 3 * 7;
print(answer);
$ oris dt.oris
42
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);