@@ -12,6 +12,16 @@ use crate::{
12 noun::{self, cell, Atom, Noun},
12 noun::{self, cell, Atom, Noun},
15+fn traverse_iter_option<T: Clone, I: Iterator<Item = Option<T>>>(xs: I) -> Option<Vec<T>> {
16+ let mut target: Vec<T> = Vec::new();
19+ target.push(x.clone()?)
15pub type Jets = BTreeMap<noun::Hash, Jet>;
25pub type Jets = BTreeMap<noun::Hash, Jet>;
17pub fn generate_jets() -> Jets {
27pub fn generate_jets() -> Jets {
@@ -54,7 +64,7 @@ pub fn generate_jets() -> Jets {
54 (288515703007942177334798811660651439897, SNAG),
64 (288515703007942177334798811660651439897, SNAG),
55 (322006565952434408151902864454572452802, SNIP),
65 (322006565952434408151902864454572452802, SNIP),
56 (290837622185731774795798043954046795930, SNOC),
66 (290837622185731774795798043954046795930, SNOC),
57− (255402796382159268271460433298209603428, SORT),
67+ // (255402796382159268271460433298209603428, SORT),
58 (10111398404342329752608067595798409804, SPIN),
68 (10111398404342329752608067595798409804, SPIN),
59 (209194119090564757355985847956576215234, SPUN),
69 (209194119090564757355985847956576215234, SPUN),
60 (103985097318911737222583881947453560061, TURN),
70 (103985097318911737222583881947453560061, TURN),
@@ -86,35 +96,38 @@ pub fn generate_jets() -> Jets {
89−pub type Jet = fn(ctx: &InterpreterContext, Rc<Noun>) -> Rc<Noun>;
99+pub type Jet = fn(ctx: &InterpreterContext, Rc<Noun>) -> Option<Rc<Noun>>;
91−static BINARY_ATOM: fn(Rc<Noun>, fn(&Atom, &Atom) -> Atom) -> Rc<Noun> =
101+static BINARY_ATOM: fn(Rc<Noun>, fn(&Atom, &Atom) -> Atom) -> Option<Rc<Noun>> =
92 |n: Rc<Noun>, f: fn(&Atom, &Atom) -> Atom| {
102 |n: Rc<Noun>, f: fn(&Atom, &Atom) -> Atom| {
93− let (p, q) = n.as_cell().unwrap();
103+ let (p, q) = n.as_cell()?;
94− Rc::new(Noun::Atom(f(p.as_atom().unwrap(), q.as_atom().unwrap())))
104+ Some(Rc::new(Noun::Atom(f(p.as_atom()?, q.as_atom()?))))
97−static BINARY_ATOM_LOOB: fn(&InterpreterContext, Rc<Noun>, fn(&Atom, &Atom) -> bool) -> Rc<Noun> =
107+static BINARY_ATOM_LOOB: fn(
108+ &InterpreterContext,
110+ fn(&Atom, &Atom) -> bool,
98− |ctx: &InterpreterContext, n: Rc<Noun>, f: fn(&Atom, &Atom) -> bool| {
111+) -> Option<Rc<Noun>> = |ctx: &InterpreterContext, n: Rc<Noun>, f: fn(&Atom, &Atom) -> bool| {
99− let (p, q) = n.as_cell().unwrap();
112+ let (p, q) = n.as_cell().unwrap();
101− if f(p.as_atom().unwrap(), q.as_atom().unwrap()) {
114+ if f(p.as_atom()?, q.as_atom()?) {
102− ctx.nouns.sig.clone()
115+ Some(ctx.nouns.sig.clone())
103− } else {
116+ } else {
104− ctx.nouns.one.clone()
117+ Some(ctx.nouns.one.clone())
108−static BINARY_ATOM_PAIR: fn(Rc<Noun>, fn(&Atom, &Atom) -> (Atom, Atom)) -> Rc<Noun> =
121+static BINARY_ATOM_PAIR: fn(Rc<Noun>, fn(&Atom, &Atom) -> (Atom, Atom)) -> Option<Rc<Noun>> =
109 |n: Rc<Noun>, f: fn(&Atom, &Atom) -> (Atom, Atom)| {
122 |n: Rc<Noun>, f: fn(&Atom, &Atom) -> (Atom, Atom)| {
110 let (p, q) = n.as_cell().unwrap();
123 let (p, q) = n.as_cell().unwrap();
112 let (a, b) = f(p.as_atom().unwrap(), q.as_atom().unwrap());
125 let (a, b) = f(p.as_atom().unwrap(), q.as_atom().unwrap());
113− cell(Rc::new(Noun::Atom(a)), Rc::new(Noun::Atom(b)))
126+ Some(cell(Rc::new(Noun::Atom(a)), Rc::new(Noun::Atom(b))))
116static ADD: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a + b);
129static ADD: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a + b);
117−static DEC: Jet = |_ctx, n| Rc::new(Noun::Atom(n.as_atom().unwrap() - 1u32));
130+static DEC: Jet = |_ctx, n| Some(Rc::new(Noun::Atom(n.as_atom().unwrap() - 1u32)));
118static DVR: Jet = |_ctx, n| BINARY_ATOM_PAIR(n, |a, b| a.div_rem(&b));
131static DVR: Jet = |_ctx, n| BINARY_ATOM_PAIR(n, |a, b| a.div_rem(&b));
119static DIV: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a / b);
132static DIV: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a / b);
120static GTE: Jet = |ctx, n| BINARY_ATOM_LOOB(ctx, n, |a, b| a >= b);
133static GTE: Jet = |ctx, n| BINARY_ATOM_LOOB(ctx, n, |a, b| a >= b);
@@ -133,7 +146,7 @@ static CAP: Jet = |ctx, n| {
134 CAP_ATOM(ctx, n)
147 CAP_ATOM(ctx, n)
136−static CAP_ATOM: fn(&InterpreterContext, Atom) -> Rc<Noun> = |ctx, n: Atom| {
149+static CAP_ATOM: fn(&InterpreterContext, Atom) -> Option<Rc<Noun>> = |ctx, n: Atom| {
137 let mut n_iter = n.iter_u32_digits();
150 let mut n_iter = n.iter_u32_digits();
139 match n_iter.len() {
152 match n_iter.len() {
@@ -142,10 +155,10 @@ static CAP_ATOM: fn(&InterpreterContext, Atom) -> Rc<Noun> = |ctx, n: Atom| {
142 _ => CAP_ATOM(ctx, n >> 1),
155 _ => CAP_ATOM(ctx, n >> 1),
145−static CAP_U32: fn(ctx: &InterpreterContext, u32) -> Rc<Noun> = |ctx, n| match n {
158+static CAP_U32: fn(ctx: &InterpreterContext, u32) -> Option<Rc<Noun>> = |ctx, n| match n {
146 0 | 1 => panic!(),
159 0 | 1 => panic!(),
147− 2 => ctx.nouns.two.clone(),
160+ 2 => Some(ctx.nouns.two.clone()),
148− 3 => ctx.nouns.three.clone(),
161+ 3 => Some(ctx.nouns.three.clone()),
149 n => CAP_U32(ctx, n >> 1),
162 n => CAP_U32(ctx, n >> 1),
@@ -153,7 +166,7 @@ static MAS: Jet = |ctx, n| {
153 let Noun::Atom(n) = (*n).clone() else {
166 let Noun::Atom(n) = (*n).clone() else {
156− Rc::new(Noun::Atom(MAS_ATOM(ctx, n)))
169+ Some(Rc::new(Noun::Atom(MAS_ATOM(ctx, n))))
158static MAS_ATOM: fn(&InterpreterContext, Atom) -> Atom = |ctx, n| {
171static MAS_ATOM: fn(&InterpreterContext, Atom) -> Atom = |ctx, n| {
159 let mut n_iter = n.iter_u32_digits();
172 let mut n_iter = n.iter_u32_digits();
@@ -182,7 +195,7 @@ static PEG: Jet = |ctx, n| {
185− Rc::new(Noun::Atom(PEG_ATOM(ctx, a, b.clone())))
198+ Some(Rc::new(Noun::Atom(PEG_ATOM(ctx, a, b.clone()))))
187static PEG_ATOM: fn(&InterpreterContext, &Atom, Atom) -> Atom = |ctx, a, b| {
200static PEG_ATOM: fn(&InterpreterContext, &Atom, Atom) -> Atom = |ctx, a, b| {
188 let mut b_iter = b.iter_u32_digits();
201 let mut b_iter = b.iter_u32_digits();
@@ -204,7 +217,7 @@ static PEG_U32: fn(&Atom, u32) -> Atom = |a, b| match b {
204static FAND: Jet = |ctx, n| {
217static FAND: Jet = |ctx, n| {
205 let (nedl, hstk) = n.as_cell().unwrap();
218 let (nedl, hstk) = n.as_cell().unwrap();
206 if nedl.is_sig() || hstk.is_sig() {
219 if nedl.is_sig() || hstk.is_sig() {
207− return ctx.nouns.sig.clone();
220+ return Some(ctx.nouns.sig.clone());
210 let nedl: Vec<Rc<Noun>> = nedl.list_iter().collect();
223 let nedl: Vec<Rc<Noun>> = nedl.list_iter().collect();
@@ -228,13 +241,13 @@ static FAND: Jet = |ctx, n| {
228 inner_iter = iter.clone();
241 inner_iter = iter.clone();
231− Noun::list(result.iter().map(|a| Noun::from_u32(*a)))
244+ Some(Noun::list(result.iter().map(|a| Noun::from_u32(*a))))
234static FIND: Jet = |ctx, n| {
247static FIND: Jet = |ctx, n| {
235 let (nedl, hstk) = n.as_cell().unwrap();
248 let (nedl, hstk) = n.as_cell().unwrap();
236 if nedl.is_sig() || hstk.is_sig() {
249 if nedl.is_sig() || hstk.is_sig() {
237− return ctx.nouns.sig.clone();
250+ return Some(ctx.nouns.sig.clone());
240 let nedl: Vec<Rc<Noun>> = nedl.list_iter().collect();
253 let nedl: Vec<Rc<Noun>> = nedl.list_iter().collect();
@@ -250,18 +263,20 @@ static FIND: Jet = |ctx, n| {
250 .collect::<Vec<_>>()
263 .collect::<Vec<_>>()
253− return Rc::new(Noun::from_u32(i)).unit();
266+ return Some(Rc::new(Noun::from_u32(i)).unit());
256 inner_iter = iter.clone();
269 inner_iter = iter.clone();
259− return ctx.nouns.sig.clone();
272+ return Some(ctx.nouns.sig.clone());
262static FLOP: Jet = |ctx, n| {
275static FLOP: Jet = |ctx, n| {
263− n.list_iter()
277+ n.list_iter()
264− .fold(ctx.nouns.sig.clone(), |tail, head| cell(head, tail))
278+ .fold(ctx.nouns.sig.clone(), |tail, head| cell(head, tail)),
267static GULF: Jet = |_ctx, n| {
282static GULF: Jet = |_ctx, n| {
@@ -281,7 +296,7 @@ static GULF: Jet = |_ctx, n| {
281 from += 1u32;
296 from += 1u32;
284− Noun::list(tmp.iter().rev().map(|a| Noun::Atom(a.clone())))
299+ Some(Noun::list(tmp.iter().rev().map(|a| Noun::Atom(a.clone()))))
287static INTO: Jet = |_ctx, n| {
302static INTO: Jet = |_ctx, n| {
@@ -291,11 +306,11 @@ static INTO: Jet = |_ctx, n| {
291 let mut b_iter = b.as_atom().unwrap().iter_u32_digits();
306 let mut b_iter = b.as_atom().unwrap().iter_u32_digits();
293 match b_iter.len() {
308 match b_iter.len() {
294− 0 => cell(c, a),
309+ 0 => Some(cell(c, a)),
296 let l = a.list_iter();
311 let l = a.list_iter();
297 let b = b_iter.next().unwrap() as usize;
312 let b = b_iter.next().unwrap() as usize;
298− Noun::list_refs(
313+ Some(Noun::list_refs(
299 l.clone()
314 l.clone()
301 .chain(once(c))
316 .chain(once(c))
@@ -303,79 +318,85 @@ static INTO: Jet = |_ctx, n| {
303 .collect::<Vec<_>>()
318 .collect::<Vec<_>>()
305 .map(|x| x.clone()),
320 .map(|x| x.clone()),
308− _ => Noun::list_refs(
323+ _ => Some(Noun::list_refs(
309 a.list_iter()
324 a.list_iter()
310 .chain(once(c))
325 .chain(once(c))
311 .collect::<Vec<_>>()
326 .collect::<Vec<_>>()
313 .map(|x| x.clone()),
328 .map(|x| x.clone()),
318static JOIN: Jet = |_ctx, n| {
333static JOIN: Jet = |_ctx, n| {
319 let (sep, list) = n.as_cell().unwrap();
334 let (sep, list) = n.as_cell().unwrap();
320− Noun::list_refs(
335+ Some(Noun::list_refs(
321 list.list_iter()
336 list.list_iter()
322 .intersperse(sep)
337 .intersperse(sep)
323 .collect::<Vec<_>>()
338 .collect::<Vec<_>>()
325 .map(|x| x.clone()),
340 .map(|x| x.clone()),
344+static LENT: Jet = |_ctx, n| {
345+ Some(Rc::new(Noun::from_u32(
329−static LENT: Jet = |_ctx, n| Rc::new(Noun::from_u32(n.list_iter().fold(0u32, |l, _| l + 1)));
346+ n.list_iter().fold(0u32, |l, _| l + 1),
331static LEVY: Jet = |ctx, n| {
350static LEVY: Jet = |ctx, n| {
332 let (a, b) = n.as_cell().unwrap();
351 let (a, b) = n.as_cell().unwrap();
333− if a.list_iter()
352+ if traverse_iter_option(a.list_iter().map(|n| slam(ctx, b.clone(), n)))?
334− .all(|n| slam(ctx, b.clone(), n) == ctx.nouns.y)
353+ .iter()
336− ctx.nouns.y.clone()
356+ Some(ctx.nouns.y.clone())
338− ctx.nouns.n.clone()
358+ Some(ctx.nouns.n.clone())
342static LIEN: Jet = |ctx, n| {
362static LIEN: Jet = |ctx, n| {
343 let (a, b) = n.as_cell().unwrap();
363 let (a, b) = n.as_cell().unwrap();
344− if a.list_iter()
364+ if traverse_iter_option(a.list_iter().map(|n| slam(ctx, b.clone(), n)))?
345− .any(|n| slam(ctx, b.clone(), n) == ctx.nouns.y)
365+ .iter()
347− ctx.nouns.y.clone()
368+ Some(ctx.nouns.y.clone())
349− ctx.nouns.n.clone()
370+ Some(ctx.nouns.n.clone())
353static MURN: Jet = |ctx, n| {
374static MURN: Jet = |ctx, n| {
354 let (a, b) = n.as_cell().unwrap();
375 let (a, b) = n.as_cell().unwrap();
356− Noun::list_refs(
377+ Some(Noun::list_refs(
357 a.list_iter()
378 a.list_iter()
358− .filter_map(|n| slam(ctx, b.clone(), n).as_unit())
379+ .filter_map(|n| slam(ctx, b.clone(), n)?.as_unit())
359 .collect::<Vec<_>>()
380 .collect::<Vec<_>>()
361 .map(|x| x.clone()),
382 .map(|x| x.clone()),
365static REAP: Jet = |_ctx, n| {
386static REAP: Jet = |_ctx, n| {
366 let (a, b) = n.as_cell().unwrap();
387 let (a, b) = n.as_cell().unwrap();
368− Noun::list_refs(repeat_n(b, a.as_u32().unwrap() as usize))
389+ Some(Noun::list_refs(repeat_n(b, a.as_u32().unwrap() as usize)))
371−static REAR: Jet = |_ctx, n| n.list_iter().last().unwrap();
392+static REAR: Jet = |_ctx, n| n.list_iter().last();
373static REEL: Jet = |ctx, n| {
394static REEL: Jet = |ctx, n| {
374 let (list, gate) = n.as_cell().unwrap();
395 let (list, gate) = n.as_cell().unwrap();
376 list.list_iter().collect::<Vec<_>>().iter().rfold(
397 list.list_iter().collect::<Vec<_>>().iter().rfold(
377− gate.clone().gate_sample().unwrap().as_cell().unwrap().1,
398+ Some(gate.clone().gate_sample()?.as_cell()?.1),
378− |acc, next| slam(ctx, gate.clone(), cell(next.clone(), acc)),
399+ |acc, next| slam(ctx, gate.clone(), cell(next.clone(), acc?)),
@@ -383,58 +404,66 @@ static ROLL: Jet = |ctx, n| {
383 let (list, gate) = n.as_cell().unwrap();
404 let (list, gate) = n.as_cell().unwrap();
385 list.list_iter().fold(
406 list.list_iter().fold(
386− gate.clone().gate_sample().unwrap().as_cell().unwrap().1,
407+ Some(gate.clone().gate_sample()?.as_cell()?.1),
387− |acc, next| slam(ctx, gate.clone(), cell(next.clone(), acc)),
408+ |acc, next| slam(ctx, gate.clone(), cell(next.clone(), acc?)),
391static SCAG: Jet = |_ctx, n| {
412static SCAG: Jet = |_ctx, n| {
392 let (a, b) = n.as_cell().unwrap();
413 let (a, b) = n.as_cell().unwrap();
394− Noun::list_refs(
415+ Some(Noun::list_refs(
395 b.list_iter()
416 b.list_iter()
396 .take(a.as_u32().unwrap() as usize)
417 .take(a.as_u32().unwrap() as usize)
397 .collect::<Vec<_>>()
418 .collect::<Vec<_>>()
399 .map(|x| x.clone()),
420 .map(|x| x.clone()),
403static SKID: Jet = |ctx, n| {
424static SKID: Jet = |ctx, n| {
404 let (list, gate) = n.as_cell().unwrap();
425 let (list, gate) = n.as_cell().unwrap();
406− let (ys, ns): (Vec<Rc<Noun>>, _) = list
427+ let slammed_n = traverse_iter_option(
407− .list_iter()
428+ list.list_iter()
408− .partition(|n| slam(ctx, gate.clone(), n.clone()).is_y());
429+ .map(|n| Some((slam(ctx, gate.clone(), n.clone())?, n))),
431+ let (ys, ns): (Vec<_>, _) = slammed_n.iter().partition(|(l, _)| l.is_y());
410− cell(
433+ Some(cell(
411− Noun::list_refs(ys.iter().cloned()),
434+ Noun::list_refs(ys.iter().map(|(_, x)| x).cloned()),
412− Noun::list_refs(ns.iter().cloned()),
435+ Noun::list_refs(ns.iter().map(|(_, x)| x).cloned()),
416static SKIM: Jet = |ctx, n| {
439static SKIM: Jet = |ctx, n| {
417 let (list, gate) = n.as_cell().unwrap();
440 let (list, gate) = n.as_cell().unwrap();
419− Noun::list_refs(
442+ Some(Noun::list_refs(
443+ traverse_iter_option(
420− list.list_iter()
444+ list.list_iter()
421− .filter(|n| slam(ctx, gate.clone(), n.clone()).is_y())
445+ .map(|n| Some((slam(ctx, gate.clone(), n.clone())?, n))),
422− .collect::<Vec<_>>()
446+ )?
448+ .filter(|(l, _)| l.is_y())
424− .cloned(),
450+ .cloned(),
428static SKIP: Jet = |ctx, n| {
454static SKIP: Jet = |ctx, n| {
429 let (list, gate) = n.as_cell().unwrap();
455 let (list, gate) = n.as_cell().unwrap();
431− Noun::list_refs(
457+ Some(Noun::list_refs(
458+ traverse_iter_option(
432− list.list_iter()
459+ list.list_iter()
433− .filter(|n| slam(ctx, gate.clone(), n.clone()).is_n())
460+ .map(|n| Some((slam(ctx, gate.clone(), n.clone())?, n))),
434− .collect::<Vec<_>>()
461+ )?
463+ .filter(|(l, _)| l.is_y())
436− .cloned(),
465+ .cloned(),
440static SLAG: Jet = |ctx, n| {
469static SLAG: Jet = |ctx, n| {
@@ -443,26 +472,26 @@ static SLAG: Jet = |ctx, n| {
443 let mut a_iter = a.as_atom().unwrap().iter_u32_digits();
472 let mut a_iter = a.as_atom().unwrap().iter_u32_digits();
445 match a_iter.len() {
474 match a_iter.len() {
446− 0 => list,
475+ 0 => Some(list),
447− 1 => Noun::list_refs(
476+ 1 => Some(Noun::list_refs(
448 list.list_iter()
477 list.list_iter()
449 .skip(a_iter.next().unwrap() as usize)
478 .skip(a_iter.next().unwrap() as usize)
450 .collect::<Vec<_>>()
479 .collect::<Vec<_>>()
452 .cloned(),
481 .cloned(),
454− _ => ctx.nouns.sig.clone(),
483+ _ => Some(ctx.nouns.sig.clone()),
458static SNAG: Jet = |_ctx, n| {
487static SNAG: Jet = |_ctx, n| {
459 let (a, list) = n.as_cell().unwrap();
488 let (a, list) = n.as_cell().unwrap();
461− list.list_iter().nth(a.as_u32().unwrap() as usize).unwrap()
490+ list.list_iter().nth(a.as_u32().unwrap() as usize)
464static SNIP: Jet = |_ctx, n| {
493static SNIP: Jet = |_ctx, n| {
465− Noun::list_refs(
494+ Some(Noun::list_refs(
466 n.list_iter()
495 n.list_iter()
467 .collect::<Vec<_>>()
496 .collect::<Vec<_>>()
@@ -470,38 +499,38 @@ static SNIP: Jet = |_ctx, n| {
472 .cloned(),
501 .cloned(),
476static SNOC: Jet = |_ctx, n| {
505static SNOC: Jet = |_ctx, n| {
477 let (list, b) = n.as_cell().unwrap();
506 let (list, b) = n.as_cell().unwrap();
479− Noun::list_refs(
508+ Some(Noun::list_refs(
480 list.list_iter()
509 list.list_iter()
481 .chain(once(b))
510 .chain(once(b))
482 .collect::<Vec<_>>()
511 .collect::<Vec<_>>()
484 .cloned(),
513 .cloned(),
488−static SORT: Jet = |ctx, n| {
517+// static SORT: Jet = |ctx, n| {
489− let (list, lth) = n.as_cell().unwrap();
518+// let (list, lth) = n.as_cell().unwrap();
491− let mut v: Vec<_> = list.list_iter().collect();
520+// let mut v: Vec<_> = list.list_iter().collect();
493− v.sort_by(|a, b| {
522+// v.sort_by(|a, b| {
494− if slam(ctx, lth.clone(), cell(a.clone(), b.clone())).is_y() {
523+// if slam(ctx, lth.clone(), cell(a.clone(), b.clone())) == ctx.nouns.some_y {
495− Ordering::Less
524+// Ordering::Less
496− } else if slam(ctx, lth.clone(), cell(b.clone(), a.clone())).is_y() {
525+// } else if slam(ctx, lth.clone(), cell(b.clone(), a.clone())) == ctx.nouns.some_y {
497− Ordering::Greater
526+// Ordering::Greater
498− } else {
527+// } else {
499− Ordering::Equal
528+// Ordering::Equal
503− Noun::list_refs(v.iter().cloned())
532+// Some(Noun::list_refs(v.iter().cloned()))
506static SPIN: Jet = |ctx, n| {
535static SPIN: Jet = |ctx, n| {
507 let (list, b) = n.as_cell().unwrap();
536 let (list, b) = n.as_cell().unwrap();
@@ -510,12 +539,12 @@ static SPIN: Jet = |ctx, n| {
510 let mut res = Vec::new();
539 let mut res = Vec::new();
512 for n in list.list_iter() {
541 for n in list.list_iter() {
513− let (el, new_acc) = slam(ctx, gate.clone(), cell(n, acc)).as_cell().unwrap();
542+ let (el, new_acc) = slam(ctx, gate.clone(), cell(n, acc))?.as_cell().unwrap();
514 acc = new_acc;
543 acc = new_acc;
515 res.push(el);
544 res.push(el);
518− cell(Noun::list_refs(res.iter().cloned()), acc)
547+ Some(cell(Noun::list_refs(res.iter().cloned()), acc))
521static SPUN: Jet = |ctx, n| {
550static SPUN: Jet = |ctx, n| {
@@ -525,51 +554,53 @@ static SPUN: Jet = |ctx, n| {
525 let mut acc = gate.clone().gate_sample().unwrap().as_cell().unwrap().1;
554 let mut acc = gate.clone().gate_sample().unwrap().as_cell().unwrap().1;
527 for n in list.list_iter() {
556 for n in list.list_iter() {
528− let (el, new_acc) = slam(ctx, gate.clone(), cell(n, acc)).as_cell().unwrap();
557+ let (el, new_acc) = slam(ctx, gate.clone(), cell(n, acc))?.as_cell().unwrap();
529 acc = new_acc;
558 acc = new_acc;
530 res.push(el);
559 res.push(el);
533− cell(Noun::list_refs(res.iter().cloned()), acc)
562+ Some(cell(Noun::list_refs(res.iter().cloned()), acc))
536static TURN: Jet = |ctx, n| {
565static TURN: Jet = |ctx, n| {
537 let (list, gate) = n.as_cell().unwrap();
566 let (list, gate) = n.as_cell().unwrap();
538− Noun::list_refs(
567+ Some(Noun::list_refs(
540− .map(|x| slam(ctx, gate.clone(), x))
568+ traverse_iter_option(list.list_iter().map(|x| slam(ctx, gate.clone(), x)))?
541− .collect::<Vec<_>>()
543 .cloned(),
570 .cloned(),
547static WELD: Jet = |_ctx, n| {
574static WELD: Jet = |_ctx, n| {
548 let (a, b) = n.as_cell().unwrap();
575 let (a, b) = n.as_cell().unwrap();
550− Noun::list_refs(
577+ Some(Noun::list_refs(
551 a.list_iter()
578 a.list_iter()
552 .chain(b.list_iter())
579 .chain(b.list_iter())
553 .collect::<Vec<_>>()
580 .collect::<Vec<_>>()
555 .cloned(),
582 .cloned(),
559static WELP: Jet = WELD;
586static WELP: Jet = WELD;
561static ZING: Jet = |_ctx, n| {
588static ZING: Jet = |_ctx, n| {
562− Noun::list_refs(
589+ Some(Noun::list_refs(
563 n.list_iter()
590 n.list_iter()
564 .map(|l| l.list_iter())
591 .map(|l| l.list_iter())
565 .flatten()
592 .flatten()
566 .collect::<Vec<_>>()
593 .collect::<Vec<_>>()
568 .cloned(),
595 .cloned(),
599+static BEX: Jet = |ctx, n| {
600+ Some(Rc::new(Noun::Atom(
572−static BEX: Jet = |ctx, n| Rc::new(Noun::Atom(&ctx.big_uints.one << n.as_u32().unwrap()));
601+ &ctx.big_uints.one << n.as_u32().unwrap(),
574static END: Jet = |ctx, n| {
605static END: Jet = |ctx, n| {
575 let (a, b) = n.as_cell().unwrap();
606 let (a, b) = n.as_cell().unwrap();
@@ -579,7 +610,7 @@ static END: Jet = |ctx, n| {
580 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
611 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
582− Rc::new(Noun::Atom(mask & b.as_atom().unwrap()))
613+ Some(Rc::new(Noun::Atom(mask & b.as_atom().unwrap())))
585static CAN: Jet = |ctx, n| {
616static CAN: Jet = |ctx, n| {
@@ -599,7 +630,7 @@ static CAN: Jet = |ctx, n| {
600 (acc << bits) | (mask & q.as_atom().unwrap())
631 (acc << bits) | (mask & q.as_atom().unwrap())
602− Rc::new(Noun::Atom(atom))
633+ Some(Rc::new(Noun::Atom(atom)))
605static CAT: Jet = |_ctx, n| {
636static CAT: Jet = |_ctx, n| {
@@ -610,9 +641,9 @@ static CAT: Jet = |_ctx, n| {
610 let b = b.as_atom().unwrap();
641 let b = b.as_atom().unwrap();
611 let c = c.as_atom().unwrap();
642 let c = c.as_atom().unwrap();
613− Rc::new(Noun::Atom(
644+ Some(Rc::new(Noun::Atom(
614 (c << (met(bloq, b.clone()) * 2u32.pow(bloq))) | b,
645 (c << (met(bloq, b.clone()) * 2u32.pow(bloq))) | b,
618static MET: Jet = |_ctx, n| {
649static MET: Jet = |_ctx, n| {
@@ -620,7 +651,7 @@ static MET: Jet = |_ctx, n| {
620 let b: Atom = b.as_atom().unwrap().clone();
651 let b: Atom = b.as_atom().unwrap().clone();
621 let bloq = bloq.as_u32().unwrap();
652 let bloq = bloq.as_u32().unwrap();
623− Rc::new(Noun::from_u32(met(bloq, b)))
654+ Some(Rc::new(Noun::from_u32(met(bloq, b))))
626fn met(bloq: u32, mut a: Atom) -> u32 {
657fn met(bloq: u32, mut a: Atom) -> u32 {
@@ -645,9 +676,9 @@ static CUT: Jet = |ctx, n| {
646 let mask = (&ctx.big_uints.one << (bits * c.as_u32().unwrap())) - &ctx.big_uints.one;
677 let mask = (&ctx.big_uints.one << (bits * c.as_u32().unwrap())) - &ctx.big_uints.one;
648− Rc::new(Noun::Atom(
679+ Some(Rc::new(Noun::Atom(
649 (d.as_atom().unwrap() >> (bits * b.as_u32().unwrap())) & mask,
680 (d.as_atom().unwrap() >> (bits * b.as_u32().unwrap())) & mask,
653static FIL: Jet = |ctx, n| {
684static FIL: Jet = |ctx, n| {
@@ -666,7 +697,7 @@ static FIL: Jet = |ctx, n| {
666 target = (target << bits) | &src;
697 target = (target << bits) | &src;
669− Rc::new(Noun::Atom(target))
700+ Some(Rc::new(Noun::Atom(target)))
672static LSH: Jet = |_ctx, n| {
703static LSH: Jet = |_ctx, n| {
@@ -674,7 +705,7 @@ static LSH: Jet = |_ctx, n| {
674 let a = a.as_bite().unwrap();
705 let a = a.as_bite().unwrap();
675 let b = b.as_atom().unwrap();
706 let b = b.as_atom().unwrap();
677− Rc::new(Noun::Atom(b << a.bits()))
708+ Some(Rc::new(Noun::Atom(b << a.bits())))
680static RSH: Jet = |_ctx, n| {
711static RSH: Jet = |_ctx, n| {
@@ -682,7 +713,7 @@ static RSH: Jet = |_ctx, n| {
682 let a = a.as_bite().unwrap();
713 let a = a.as_bite().unwrap();
683 let b = b.as_atom().unwrap();
714 let b = b.as_atom().unwrap();
685− Rc::new(Noun::Atom(b >> a.bits()))
716+ Some(Rc::new(Noun::Atom(b >> a.bits())))
688static RAP: Jet = |ctx, n| {
719static RAP: Jet = |ctx, n| {
@@ -699,7 +730,7 @@ static RAP: Jet = |ctx, n| {
702− Rc::new(Noun::Atom(target))
733+ Some(Rc::new(Noun::Atom(target)))
705static REP: Jet = |ctx, n| {
736static REP: Jet = |ctx, n| {
@@ -715,7 +746,7 @@ static REP: Jet = |ctx, n| {
715 target = (target << bits) | (el.as_atom().unwrap() & &mask);
746 target = (target << bits) | (el.as_atom().unwrap() & &mask);
718− Rc::new(Noun::Atom(target))
749+ Some(Rc::new(Noun::Atom(target)))
721static REV: Jet = |ctx, n| {
752static REV: Jet = |ctx, n| {
@@ -735,7 +766,7 @@ static REV: Jet = |ctx, n| {
735 dat = dat >> bits;
766 dat = dat >> bits;
738− Rc::new(Noun::Atom(target))
769+ Some(Rc::new(Noun::Atom(target)))
741static RIP: Jet = |ctx, n| {
772static RIP: Jet = |ctx, n| {
@@ -753,7 +784,7 @@ static RIP: Jet = |ctx, n| {
753 b = b >> bits;
784 b = b >> bits;
756− Noun::list_refs(target.iter().cloned())
787+ Some(Noun::list_refs(target.iter().cloned()))
759static RUN: Jet = |ctx, n| {
790static RUN: Jet = |ctx, n| {
@@ -770,14 +801,14 @@ static RUN: Jet = |ctx, n| {
771 while b > ctx.big_uints.zero {
802 while b > ctx.big_uints.zero {
772 target = (target << bits)
803 target = (target << bits)
773− | ((*slam(ctx, gate.clone(), Rc::new(Noun::Atom(&mask & &b))))
804+ | ((*slam(ctx, gate.clone(), Rc::new(Noun::Atom(&mask & &b)))?)
774 .as_atom()
805 .as_atom()
775 .unwrap()
806 .unwrap()
776 & &mask);
807 & &mask);
777 b = b >> bits;
808 b = b >> bits;
780− Rc::new(Noun::Atom(target))
811+ Some(Rc::new(Noun::Atom(target)))
783static RUT: Jet = |ctx, n| {
814static RUT: Jet = |ctx, n| {
@@ -794,7 +825,7 @@ static RUT: Jet = |ctx, n| {
795 while b > ctx.big_uints.zero {
826 while b > ctx.big_uints.zero {
796 target.push(
827 target.push(
797− (*slam(ctx, gate.clone(), Rc::new(Noun::Atom(&mask & &b))))
828+ (*slam(ctx, gate.clone(), Rc::new(Noun::Atom(&mask & &b)))?)
798 .as_atom()
829 .as_atom()
799 .unwrap()
830 .unwrap()
@@ -802,7 +833,7 @@ static RUT: Jet = |ctx, n| {
802 b = b >> bits;
833 b = b >> bits;
805− Noun::list(target.iter().cloned().map(Noun::Atom))
836+ Some(Noun::list(target.iter().cloned().map(Noun::Atom)))
808static SEW: Jet = |ctx, n| {
839static SEW: Jet = |ctx, n| {
@@ -823,7 +854,7 @@ static SEW: Jet = |ctx, n| {
824 let target = (recipient ^ apendix) | (donor & mask);
855 let target = (recipient ^ apendix) | (donor & mask);
826− Rc::new(Noun::Atom(target))
857+ Some(Rc::new(Noun::Atom(target)))
829static SWP: Jet = |ctx, n| {
860static SWP: Jet = |ctx, n| {
@@ -840,7 +871,7 @@ static SWP: Jet = |ctx, n| {
840 source = source >> bits;
871 source = source >> bits;
843− Rc::new(Noun::Atom(target))
874+ Some(Rc::new(Noun::Atom(target)))
846static XEB: Jet = |_ctx, n| {
877static XEB: Jet = |_ctx, n| {
@@ -853,7 +884,7 @@ static XEB: Jet = |_ctx, n| {
856− Rc::new(Noun::from_u32(c))
887+ Some(Rc::new(Noun::from_u32(c)))
859static CON: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a | b);
890static CON: Jet = |_ctx, n| BINARY_ATOM(n, |a, b| a | b);
@@ -870,5 +901,5 @@ static NOT: Jet = |ctx, n| {
871 let target = c.as_atom().unwrap() ^ &mask;
902 let target = c.as_atom().unwrap() ^ &mask;
873− Rc::new(Noun::Atom(target))
904+ Some(Rc::new(Noun::Atom(target)))