aboutsummaryrefslogtreecommitdiff
path: root/src/sexp/step.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/sexp/step.rs')
-rw-r--r--src/sexp/step.rs62
1 files changed, 38 insertions, 24 deletions
diff --git a/src/sexp/step.rs b/src/sexp/step.rs
index 5b60fec..84553e1 100644
--- a/src/sexp/step.rs
+++ b/src/sexp/step.rs
@@ -1,6 +1,5 @@
use crate::sexp::{SExp, SExp::*, SLeaf::*, util::*};
-use crate::r#type::{Type::*, util::*};
impl SExp {
@@ -346,6 +345,31 @@ impl SExp {
None => panic!("unreachable as per match guard arm"),
},
+ // Custom anonymous functions
+ SCons(op, l) if (*op).is_fun() => {
+
+ // Get function parts
+ let ls = op.parts();
+ let argnames = ls.get(1).unwrap()
+ .clone().parts();
+ let mut argnamevec = vec![];
+ for name in argnames.clone() {
+ argnamevec.push(match name {
+ Atom(Var(s)) => Ok(s),
+ _ => Err("invalid entry in argument list (should be unreachable after type checker)".to_string()),
+ }?);
+ }
+ let mut body = ls.get(4).unwrap().clone();
+
+ // Get argument parts
+ let suppliedargs = l.parts();
+ for (name, value) in argnamevec.into_iter().zip(suppliedargs) {
+ body = body.subst(&name, &value);
+ }
+
+ Ok(body)
+ },
+
// case expressions
SCons(op, l) if scons(op.clone(), l.clone()).check_case().is_some() => {
let (scrutinee, patarms) = scons(op, l).check_case().unwrap();
@@ -394,29 +418,19 @@ impl SExp {
},
- // Custom anonymous functions
- SCons(op, l) if (*op).is_fun() => {
-
- // Get function parts
- let ls = op.parts();
- let argnames = ls.get(1).unwrap()
- .clone().parts();
- let mut argnamevec = vec![];
- for name in argnames.clone() {
- argnamevec.push(match name {
- Atom(Var(s)) => Ok(s),
- _ => Err("invalid entry in argument list (should be unreachable after type checker)".to_string()),
- }?);
- }
- let mut body = ls.get(4).unwrap().clone();
-
- // Get argument parts
- let suppliedargs = l.parts();
- for (name, value) in argnamevec.into_iter().zip(suppliedargs) {
- body = body.subst(&name, &value);
- }
-
- Ok(body)
+ // Fixed point recursion
+ SCons(op, l) if *op == Atom(Fix) => {
+ let ls = match (*l).clone() {
+ SCons(a, n) if *n == Atom(Nil) => a.clone(),
+ _ => todo!()
+ }.parts();
+ let argls = ls[1].clone();
+ let argname = match argls {
+ Atom(Var(name)) => name,
+ _ => todo!()
+ };
+ let body = ls[4].clone();
+ Ok(body.subst(&argname, &scons(op, l)))
},