diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-15 15:21:31 +0300 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-15 15:21:31 +0300 |
commit | 233b91f20e9b7ede3a2aa25ee9f1342b216f30b0 (patch) | |
tree | a63f9f0d98fba768ee5673f71af7a7a27b1e9473 | |
parent | 0ca4c3f103acd9d1ea78bbc42b9b70161a94308d (diff) | |
download | myslip-233b91f20e9b7ede3a2aa25ee9f1342b216f30b0.tar.gz myslip-233b91f20e9b7ede3a2aa25ee9f1342b216f30b0.zip |
fix: function arguments not evaluating before function call
-rw-r--r-- | src/sexp/step.rs | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/src/sexp/step.rs b/src/sexp/step.rs index 84553e1..99925ac 100644 --- a/src/sexp/step.rs +++ b/src/sexp/step.rs @@ -345,31 +345,6 @@ 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(); @@ -417,6 +392,30 @@ impl SExp { Ok(scons(op, inner(*l)?)) }, + // 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) => { |