fix evaluation behavior mismatch between functions and lambdas

Signed-off-by: Ava Hahn <ava@sunnypup.io>
This commit is contained in:
Ava Apples Affine 2023-06-08 12:48:34 -07:00
parent e0b837cb21
commit 398726568a
4 changed files with 41 additions and 13 deletions

View file

@ -1,6 +1,7 @@
mod eval_tests {
use relish::ast::{eval, lex, SymTable};
use relish::ast::{Args, Ctr, Seg, Symbol, UserFn, ValueType};
use relish::stdlib::{dynamic_stdlib, static_stdlib};
#[test]
fn eval_simple() {
@ -92,4 +93,21 @@ mod eval_tests {
}
}
}
#[test]
fn func_lambda_equivalency() {
let comparator = "(def apply 'applicator' (fn x) (fn x))";
let lh_doc = "(apply car (1 2 3))";
let rh_doc = "(apply (lambda (x) (car x)) (1 2 3))";
let mut syms = SymTable::new();
static_stdlib(&mut syms);
dynamic_stdlib(&mut syms, None);
eval(&lex(&comparator.to_string()).unwrap(), &mut syms).unwrap();
assert_eq!(
eval(&lex(&lh_doc.to_string()).unwrap(), &mut syms).unwrap(),
eval(&lex(&rh_doc.to_string()).unwrap(), &mut syms).unwrap(),
);
}
}