on master help sign in
reel
commitc076006055d3aa8cc256ef3debf9681003e56fc0 authoriko <mail@iko.soy> dateFri 23 Aug 2024, 14:47 (2 years ago) parent0af3020
3 files changed+21−5
nock/src/interpreter.rs+1−1 nock/src/jets.rs+14−4 nock/src/noun.rs+6
nock/src/interpreter.rs+1−1
@@ -321,7 +321,7 @@ pub fn eval_gate(ctx: &InterpreterContext, gate: Rc<Noun>) -> Rc<Noun> {
321321 )
322322}
323323
324−pub fn call_gate(ctx: &InterpreterContext, gate: Rc<Noun>, sample: Rc<Noun>) -> Rc<Noun> {
324+pub fn slam(ctx: &InterpreterContext, gate: Rc<Noun>, sample: Rc<Noun>) -> Rc<Noun> {
325325 let (battery, payload) = gate.as_cell().unwrap();
326326 let (_sample, context) = payload.as_cell().unwrap();
327327
nock/src/jets.rs+14−4
@@ -7,7 +7,7 @@ use std::{
77};
88
99use crate::{
10− interpreter::{call_gate, InterpreterContext},
10+ interpreter::{slam, InterpreterContext},
1111 noun::{self, cell, Atom, Noun},
1212};
1313
@@ -43,6 +43,7 @@ pub fn generate_jets() -> Jets {
4343 (134383540064775397895881415210519251023, MURN),
4444 (206209714924463645290290379601675245373, REAP),
4545 (266278769253331237088430651317345081031, REAR),
46+ (146282575960509029931248602154898675358, REEL),
4647 ])
4748}
4849
@@ -296,7 +297,7 @@ static LENT: Jet = |_ctx, n| Rc::new(Noun::from_u32(n.list_iter().fold(0u32, |l,
296297static LEVY: Jet = |ctx, n| {
297298 let (a, b) = n.as_cell().unwrap();
298299 if a.list_iter()
299− .all(|n| call_gate(ctx, b.clone(), n) == ctx.nouns.y)
300+ .all(|n| slam(ctx, b.clone(), n) == ctx.nouns.y)
300301 {
301302 ctx.nouns.y.clone()
302303 } else {
@@ -307,7 +308,7 @@ static LEVY: Jet = |ctx, n| {
307308static LIEN: Jet = |ctx, n| {
308309 let (a, b) = n.as_cell().unwrap();
309310 if a.list_iter()
310− .any(|n| call_gate(ctx, b.clone(), n) == ctx.nouns.y)
311+ .any(|n| slam(ctx, b.clone(), n) == ctx.nouns.y)
311312 {
312313 ctx.nouns.y.clone()
313314 } else {
@@ -320,7 +321,7 @@ static MURN: Jet = |ctx, n| {
320321
321322 Noun::list_refs(
322323 a.list_iter()
323− .filter_map(|n| call_gate(ctx, b.clone(), n).as_unit())
324+ .filter_map(|n| slam(ctx, b.clone(), n).as_unit())
324325 .collect::<Vec<_>>()
325326 .iter()
326327 .map(|x| x.clone()),
@@ -334,3 +335,12 @@ static REAP: Jet = |_ctx, n| {
334335};
335336
336337static REAR: Jet = |_ctx, n| n.list_iter().last().unwrap();
338+
339+static REEL: Jet = |ctx, n| {
340+ let (list, gate) = n.as_cell().unwrap();
341+
342+ list.list_iter().collect::<Vec<_>>().iter().rfold(
343+ gate.clone().gate_sample().unwrap().as_cell().unwrap().1,
344+ |acc, next| slam(ctx, gate.clone(), cell(next.clone(), acc)),
345+ )
346+};
nock/src/noun.rs+6
@@ -76,6 +76,12 @@ impl Noun {
7676 }
7777 }
7878
79+ pub fn gate_sample(self: Rc<Self>) -> Option<Rc<Self>> {
80+ let (_battery, payload) = self.as_cell()?;
81+ let (sample, _context) = payload.as_cell()?;
82+ Option::Some(sample)
83+ }
84+
7985 pub fn as_cell(self: &Self) -> Option<(Rc<Noun>, Rc<Noun>)> {
8086 match self {
8187 Noun::Cell { p, q, .. } => Option::Some((p.clone(), q.clone())),