on master help sign in
levy
commit42812eb8d23803db81342c735e2cb9dc5ebebde6 authoriko <mail@iko.soy> dateThu 22 Aug 2024, 12:29 (2 years ago) parenta2ab8d5
2 files changed+20−1
nock/src/interpreter.rs+7 nock/src/jets.rs+13−1
nock/src/interpreter.rs+7
@@ -320,3 +320,10 @@ pub fn eval_gate(ctx: &InterpreterContext, gate: Rc<Noun>) -> Rc<Noun> {
320320 ),
321321 )
322322}
323+
324+pub fn call_gate(ctx: &InterpreterContext, gate: Rc<Noun>, sample: Rc<Noun>) -> Rc<Noun> {
325+ let (battery, payload) = gate.as_cell().unwrap();
326+ let (_sample, context) = payload.as_cell().unwrap();
327+
328+ eval_gate(ctx, cell(battery, cell(sample, context)))
329+}
nock/src/jets.rs+13−1
@@ -7,7 +7,7 @@ use std::{
77};
88
99use crate::{
10− interpreter::InterpreterContext,
10+ interpreter::{call_gate, InterpreterContext},
1111 noun::{self, cell, Atom, Noun},
1212};
1313
@@ -38,6 +38,7 @@ pub fn generate_jets() -> Jets {
3838 (224124632134128248273067864092142254001, INTO),
3939 (22365719601138689598430859488399820563, JOIN),
4040 (211253539934007667533839299235896640130, LENT),
41+ (104838119266193725126177792605193739824, LEVY),
4142 ])
4243}
4344
@@ -287,3 +288,14 @@ static JOIN: Jet = |_ctx, n| {
287288};
288289
289290static LENT: Jet = |_ctx, n| Rc::new(Noun::from_u32(n.list_iter().fold(0u32, |l, _| l + 1)));
291+
292+static LEVY: Jet = |ctx, n| {
293+ let (a, b) = n.as_cell().unwrap();
294+ if a.list_iter()
295+ .all(|n| call_gate(ctx, b.clone(), n) == ctx.nouns.y)
296+ {
297+ ctx.nouns.y.clone()
298+ } else {
299+ ctx.nouns.n.clone()
300+ }
301+};