on master help sign in
reel
c076006iko
nock/src/interpreter.rs+1−1
@@ -321,7 +321,7 @@ pub fn eval_gate(ctx: &InterpreterContext, gate: Rc<Noun>) -> Rc<Noun> {
321 )
321 )
322}
322}
323
323
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> {
325 let (battery, payload) = gate.as_cell().unwrap();
325 let (battery, payload) = gate.as_cell().unwrap();
326 let (_sample, context) = payload.as_cell().unwrap();
326 let (_sample, context) = payload.as_cell().unwrap();
327
327
nock/src/jets.rs+14−4
@@ -7,7 +7,7 @@ use std::{
7};
7};
8
8
9use crate::{
9use crate::{
10− interpreter::{call_gate, InterpreterContext},
10+ interpreter::{slam, InterpreterContext},
11 noun::{self, cell, Atom, Noun},
11 noun::{self, cell, Atom, Noun},
12};
12};
13
13
@@ -43,6 +43,7 @@ pub fn generate_jets() -> Jets {
43 (134383540064775397895881415210519251023, MURN),
43 (134383540064775397895881415210519251023, MURN),
44 (206209714924463645290290379601675245373, REAP),
44 (206209714924463645290290379601675245373, REAP),
45 (266278769253331237088430651317345081031, REAR),
45 (266278769253331237088430651317345081031, REAR),
46+ (146282575960509029931248602154898675358, REEL),
46 ])
47 ])
47}
48}
48
49
@@ -296,7 +297,7 @@ static LENT: Jet = |_ctx, n| Rc::new(Noun::from_u32(n.list_iter().fold(0u32, |l,
296static LEVY: Jet = |ctx, n| {
297static LEVY: Jet = |ctx, n| {
297 let (a, b) = n.as_cell().unwrap();
298 let (a, b) = n.as_cell().unwrap();
298 if a.list_iter()
299 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)
300 {
301 {
301 ctx.nouns.y.clone()
302 ctx.nouns.y.clone()
302 } else {
303 } else {
@@ -307,7 +308,7 @@ static LEVY: Jet = |ctx, n| {
307static LIEN: Jet = |ctx, n| {
308static LIEN: Jet = |ctx, n| {
308 let (a, b) = n.as_cell().unwrap();
309 let (a, b) = n.as_cell().unwrap();
309 if a.list_iter()
310 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)
311 {
312 {
312 ctx.nouns.y.clone()
313 ctx.nouns.y.clone()
313 } else {
314 } else {
@@ -320,7 +321,7 @@ static MURN: Jet = |ctx, n| {
320
321
321 Noun::list_refs(
322 Noun::list_refs(
322 a.list_iter()
323 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())
324 .collect::<Vec<_>>()
325 .collect::<Vec<_>>()
325 .iter()
326 .iter()
326 .map(|x| x.clone()),
327 .map(|x| x.clone()),
@@ -334,3 +335,12 @@ static REAP: Jet = |_ctx, n| {
334};
335};
335
336
336static REAR: Jet = |_ctx, n| n.list_iter().last().unwrap();
337static 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 {
76 }
76 }
77 }
77 }
78
78
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+
79 pub fn as_cell(self: &Self) -> Option<(Rc<Noun>, Rc<Noun>)> {
85 pub fn as_cell(self: &Self) -> Option<(Rc<Noun>, Rc<Noun>)> {
80 match self {
86 match self {
81 Noun::Cell { p, q, .. } => Option::Some((p.clone(), q.clone())),
87 Noun::Cell { p, q, .. } => Option::Some((p.clone(), q.clone())),