aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-03-24 07:47:54 +0000
committerAkshay <[email protected]>2021-03-24 07:47:54 +0000
commit1a152b5cdaf3e636a5f495e81895d35d0f841c44 (patch)
tree045b9f64e9c6793527a267c253c7fdf7b6df11ab
parentccb17fedaa4587879778e250c8adaf847d71fd90 (diff)
implement boolean primitives; `begin` form
-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