on master help sign in
reap
1f34a7eiko
nock/src/jets.rs+8−1
@@ -2,7 +2,7 @@ use core::panic;
2use num_integer::Integer;
2use num_integer::Integer;
3use std::{
3use std::{
4 collections::BTreeMap,
4 collections::BTreeMap,
5− iter::{once, zip},
5+ iter::{once, repeat_n, zip},
6 rc::Rc,
6 rc::Rc,
7};
7};
8
8
@@ -41,6 +41,7 @@ pub fn generate_jets() -> Jets {
41 (104838119266193725126177792605193739824, LEVY),
41 (104838119266193725126177792605193739824, LEVY),
42 (136665047491594821996133547576675424469, LIEN),
42 (136665047491594821996133547576675424469, LIEN),
43 (134383540064775397895881415210519251023, MURN),
43 (134383540064775397895881415210519251023, MURN),
44+ (206209714924463645290290379601675245373, REAP),
44 ])
45 ])
45}
46}
46
47
@@ -324,3 +325,9 @@ static MURN: Jet = |ctx, n| {
324 .map(|x| x.clone()),
325 .map(|x| x.clone()),
325 )
326 )
326};
327};
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 @@
1#![feature(iter_intersperse)]
1#![feature(iter_intersperse)]
2+#![feature(iter_repeat_n)]
2pub mod interpreter;
3pub mod interpreter;
3mod jets;
4mod jets;
4pub mod noun;
5pub mod noun;
nock/src/noun.rs+11
@@ -65,6 +65,17 @@ impl Noun {
65 _ => Option::None,
65 _ => Option::None,
66 }
66 }
67 }
67 }
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+
68 pub fn as_cell(self: &Self) -> Option<(Rc<Noun>, Rc<Noun>)> {
79 pub fn as_cell(self: &Self) -> Option<(Rc<Noun>, Rc<Noun>)> {
69 match self {
80 match self {
70 Noun::Cell { p, q, .. } => Option::Some((p.clone(), q.clone())),
81 Noun::Cell { p, q, .. } => Option::Some((p.clone(), q.clone())),