on master help sign in
reap
commit1f34a7ee60b2eae3e5864de55692af201b50e78b authoriko <mail@iko.soy> dateThu 22 Aug 2024, 22:34 (2 years ago) parent32dbe2d
3 files changed+20−1
nock/src/jets.rs+8−1 nock/src/lib.rs+1 nock/src/noun.rs+11
nock/src/jets.rs+8−1
@@ -2,7 +2,7 @@ use core::panic;
22use num_integer::Integer;
33use std::{
44 collections::BTreeMap,
5− iter::{once, zip},
5+ iter::{once, repeat_n, zip},
66 rc::Rc,
77};
88
@@ -41,6 +41,7 @@ pub fn generate_jets() -> Jets {
4141 (104838119266193725126177792605193739824, LEVY),
4242 (136665047491594821996133547576675424469, LIEN),
4343 (134383540064775397895881415210519251023, MURN),
44+ (206209714924463645290290379601675245373, REAP),
4445 ])
4546}
4647
@@ -324,3 +325,9 @@ static MURN: Jet = |ctx, n| {
324325 .map(|x| x.clone()),
325326 )
326327};
328+
329+static REAP: Jet = |_ctx, n| {
330+ let (a, b) = n.as_cell().unwrap();
331+
332+ Noun::list_refs(repeat_n(b, a.as_u32().unwrap() as usize))
333+};
nock/src/lib.rs+1
@@ -1,4 +1,5 @@
11#![feature(iter_intersperse)]
2+#![feature(iter_repeat_n)]
23pub mod interpreter;
34mod jets;
45pub mod noun;
nock/src/noun.rs+11
@@ -65,6 +65,17 @@ impl Noun {
6565 _ => Option::None,
6666 }
6767 }
68+
69+ pub fn as_u32(self: &Self) -> Option<u32> {
70+ let mut iter = self.as_atom()?.iter_u32_digits();
71+
72+ match iter.len() {
73+ 0 => Some(0),
74+ 1 => Some(iter.next().unwrap()),
75+ _ => Option::None,
76+ }
77+ }
78+
6879 pub fn as_cell(self: &Self) -> Option<(Rc<Noun>, Rc<Noun>)> {
6980 match self {
7081 Noun::Cell { p, q, .. } => Option::Some((p.clone(), q.clone())),