aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lisp/env.rs31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/lisp/env.rs b/src/lisp/env.rs
index 6338f91..c5ff6d3 100644
--- a/src/lisp/env.rs
+++ b/src/lisp/env.rs
@@ -67,7 +67,7 @@ pub fn with_prelude() -> Environment {
67 } 67 }
68 } 68 }
69 }); 69 });
70 primitive!(env, Some(1), "and", |args, _| { 70 primitive!(env, Some(2), "and", |args, _| {
71 if args 71 if args
72 .iter() 72 .iter()
73 .any(|arg| matches!(arg, LispExpr::BoolLit(false))) 73 .any(|arg| matches!(arg, LispExpr::BoolLit(false)))
@@ -77,6 +77,35 @@ pub fn with_prelude() -> Environment {
77 Ok(LispExpr::BoolLit(true)) 77 Ok(LispExpr::BoolLit(true))
78 } 78 }
79 }); 79 });
80 primitive!(env, Some(2), "or", |args, _| {
81 if args
82 .iter()
83 .any(|arg| matches!(arg, LispExpr::BoolLit(true)))
84 {
85 Ok(LispExpr::BoolLit(true))
86 } else {
87 Ok(LispExpr::BoolLit(false))
88 }
89 });
90 primitive!(env, Some(1), "not", |args, _| {
91 match args {
92 [val] => {
93 if matches!(val, LispExpr::BoolLit(false)) {
94 Ok(LispExpr::BoolLit(true))
95 } else {
96 Ok(LispExpr::BoolLit(false))
97 }
98 }
99 _ => Err(LispError::EvalError),
100 }
101 });
102 primitive!(env, None, "begin", |args, _| {
103 if args.is_empty() {
104 Err(LispError::EvalError)
105 } else {
106 Ok(args.into_iter().last().unwrap().clone())
107 }
108 });
80 env 109 env
81} 110}
82 111