fix: closures are functions, functions are closures
This commit is contained in:
parent
e6b487a09a
commit
527737f020
3 changed files with 4 additions and 28 deletions
3
src/env/core.rs
vendored
3
src/env/core.rs
vendored
|
@ -313,6 +313,7 @@ pub(super) fn core() -> HashMap<String, Node> {
|
|||
|
||||
let func = Node::Function {
|
||||
params: args,
|
||||
env: env.clone(),
|
||||
body: Box::new(body),
|
||||
};
|
||||
|
||||
|
@ -364,7 +365,7 @@ pub(super) fn core() -> HashMap<String, Node> {
|
|||
_ => Err(Error::ExpectedList),
|
||||
}?;
|
||||
|
||||
Ok(Node::Closure {
|
||||
Ok(Node::Function {
|
||||
params: args,
|
||||
env: env.clone(),
|
||||
body: Box::new(body),
|
||||
|
|
|
@ -47,24 +47,7 @@ pub fn eval_node(env: &Environment, ast_node: Node) -> Result<Node> {
|
|||
let args = list.collect();
|
||||
func(env, args)?
|
||||
}
|
||||
|
||||
Node::Function { params, body } => {
|
||||
let args = list;
|
||||
if args.len() != params.len() {
|
||||
Err(Error::MismatchedArgCount(params.len(), args.len()))?
|
||||
}
|
||||
|
||||
let args = args
|
||||
.map(|node| eval_node(env, node))
|
||||
.collect::<Result<Vec<Node>>>()?;
|
||||
|
||||
let records = params.iter().map(|k| k.to_owned()).zip(args).collect();
|
||||
let env = env.wrap(records);
|
||||
|
||||
eval_node(&env, *(*body).clone())?
|
||||
}
|
||||
|
||||
Node::Closure {
|
||||
Node::Function {
|
||||
params,
|
||||
env: inner_env,
|
||||
body,
|
||||
|
|
10
src/node.rs
10
src/node.rs
|
@ -18,10 +18,6 @@ pub enum Node {
|
|||
Vector(Vec<Node>),
|
||||
Map(HashMap<String, Node>),
|
||||
Function {
|
||||
params: Vec<String>,
|
||||
body: Box<Node>,
|
||||
},
|
||||
Closure {
|
||||
params: Vec<String>,
|
||||
env: Environment,
|
||||
body: Box<Node>,
|
||||
|
@ -72,11 +68,7 @@ impl std::fmt::Display for Node {
|
|||
write!(f, "{{{res}}}")
|
||||
}
|
||||
|
||||
Node::Function { params: _, body: _ } => {
|
||||
write!(f, "#<function>")
|
||||
}
|
||||
|
||||
Node::Closure {
|
||||
Node::Function {
|
||||
params: _,
|
||||
env: _,
|
||||
body: _,
|
||||
|
|
Loading…
Reference in a new issue