fix(eval): early eval of arguments to functions
This commit is contained in:
parent
8f1b1840ad
commit
9abe404925
@ -85,7 +85,7 @@ fn dispatch_anonymous_function(
|
||||
}
|
||||
|
||||
for (arg, symbol) in args.iter_mut().zip(argument_symbols.iter()) {
|
||||
overlay.set(symbol.to_owned(), arg.to_owned());
|
||||
overlay.set(symbol.to_owned(), eval(env, arg.to_owned())?);
|
||||
}
|
||||
|
||||
eval(&env.overlay(overlay), body)
|
||||
|
||||
@ -161,10 +161,11 @@ pub fn prelude_gt(env: &Environment, expr: Expression) -> Result<Expression, Eva
|
||||
pub fn prelude_set(env: &Environment, expr: Expression) -> Result<Expression, EvalError> {
|
||||
let [s, e] = expr.try_into()?;
|
||||
|
||||
match s {
|
||||
match eval(env, s)? {
|
||||
Expression::Symbol(s) => {
|
||||
env.shared_set(s, e);
|
||||
Ok(Expression::Nil)
|
||||
let e = eval(env, e)?;
|
||||
env.shared_set(s, e.clone());
|
||||
Ok(e)
|
||||
}
|
||||
x => Err(EvalError::NotASymbol(x)),
|
||||
}
|
||||
|
||||
@ -6,8 +6,8 @@ use crate::lisp::{eval, Environment};
|
||||
|
||||
fn main() {
|
||||
let program1 = "((lambda (x y) (+ (if (< x 10) (* x 11) x) y)) 2 20)";
|
||||
let program2 = "(set myvar \"hello world!\")";
|
||||
let program3 = "(print myvar)";
|
||||
let program2 = "(set 'myvar \"hello world!\")";
|
||||
let program3 = "(print myvar) (print 'myvar)";
|
||||
|
||||
let environment = Environment::default();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user