diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-15 11:27:52 +0300 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-15 11:27:52 +0300 |
commit | 0ca4c3f103acd9d1ea78bbc42b9b70161a94308d (patch) | |
tree | 7e8144434656f44e2e1f66175bb80ec6364a6ce5 /src/sexp/step.rs | |
parent | 322f541d6922422e5a4aa29f50c6534517ee85be (diff) | |
download | myslip-0ca4c3f103acd9d1ea78bbc42b9b70161a94308d.tar.gz myslip-0ca4c3f103acd9d1ea78bbc42b9b70161a94308d.zip |
feat: fixed point dynamics
Diffstat (limited to 'src/sexp/step.rs')
-rw-r--r-- | src/sexp/step.rs | 62 |
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))) }, |