add noexec operator to pass named functions to functions

This commit is contained in:
2024-10-16 17:04:25 -04:00
parent d0661512c9
commit 329af77ff4
3 changed files with 23 additions and 2 deletions

View File

@@ -353,6 +353,24 @@ where
}
}
ParseTree::LambdaDefinition(func) => Ok(Value::Function(func)),
ParseTree::NonCall(name) => {
let locals = locals.to_mut();
let func = locals.get(&name).ok_or(RuntimeError::FunctionUndefined(name.clone())).cloned()?;
match func {
Object::Function(func) => Ok(Value::Function(func.clone())),
Object::Variable(var) => match var {
Evaluation::Computed(value) => Ok(value.clone()),
Evaluation::Uncomputed(tree) => {
let v = self.exec(tree, &mut Cow::Borrowed(&locals))?;
locals.insert(name, Object::Variable(Evaluation::Computed(v.clone())));
Ok(v)
}
}
}
}
}
}
}