aboutsummaryrefslogtreecommitdiff
path: root/src/lisp/eval.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lisp/eval.rs')
-rw-r--r--src/lisp/eval.rs14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/lisp/eval.rs b/src/lisp/eval.rs
index b404662..75cb5c9 100644
--- a/src/lisp/eval.rs
+++ b/src/lisp/eval.rs
@@ -71,11 +71,7 @@ where
71 let nested_env: Environment = 71 let nested_env: Environment =
72 f.params.clone().into_iter().zip(args).collect(); 72 f.params.clone().into_iter().zip(args).collect();
73 self.app.lisp_env.push(nested_env); 73 self.app.lisp_env.push(nested_env);
74 let result = if f.body.is_empty() { 74 let result = self.eval(&f.body);
75 Ok(LispExpr::Unit)
76 } else {
77 self.eval(&LispExpr::List(f.body.clone()))
78 };
79 self.app.lisp_env.pop(); 75 self.app.lisp_env.pop();
80 result 76 result
81 } 77 }
@@ -111,7 +107,7 @@ where
111 } 107 }
112 Ok(LispExpr::Unit) 108 Ok(LispExpr::Unit)
113 } 109 }
114 [LispExpr::List(shorthand), LispExpr::List(body)] => { 110 [LispExpr::List(shorthand), body] => {
115 // (define (func arg) <body>) shorthand 111 // (define (func arg) <body>) shorthand
116 112
117 let id = shorthand[0].unwrap_ident(); 113 let id = shorthand[0].unwrap_ident();
@@ -126,7 +122,7 @@ where
126 .collect::<Result<Vec<Ident>, LispError>>()?; 122 .collect::<Result<Vec<Ident>, LispError>>()?;
127 let value = LispExpr::Function(LispFunction { 123 let value = LispExpr::Function(LispFunction {
128 params, 124 params,
129 body: body.to_vec(), 125 body: Box::new(body.clone()),
130 }); 126 });
131 127
132 let local_env = &mut self.app.lisp_env.last_mut(); 128 let local_env = &mut self.app.lisp_env.last_mut();
@@ -327,10 +323,10 @@ pub fn create_lambda(cdr: &[LispExpr]) -> Result<LispExpr, LispError> {
327 return Err(arity.to_error()); 323 return Err(arity.to_error());
328 } 324 }
329 match cdr { 325 match cdr {
330 [LispExpr::List(params), LispExpr::List(body)] if type_match!(params, (..) => LispExpr::Ident(_)) => { 326 [LispExpr::List(params), body] if type_match!(params, (..) => LispExpr::Ident(_)) => {
331 Ok(LispExpr::Function(LispFunction { 327 Ok(LispExpr::Function(LispFunction {
332 params: params.iter().map(|p| p.unwrap_ident()).collect::<Vec<_>>(), 328 params: params.iter().map(|p| p.unwrap_ident()).collect::<Vec<_>>(),
333 body: body.clone(), 329 body: Box::new(body.clone()),
334 })) 330 }))
335 } 331 }
336 _ => { 332 _ => {