Skip to content

Commit

Permalink
Added and and or
Browse files Browse the repository at this point in the history
  • Loading branch information
ellamental committed Sep 3, 2010
1 parent 6591bca commit 6678871
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
24 changes: 22 additions & 2 deletions lispy.c
Expand Up @@ -1118,12 +1118,32 @@ object *eval(object *exp, object *env) {

/** and **/
else if (is_primitive_syntax(exp, and_symbol)) {
error("and not implemented yet");
exp = cdr(exp);
while (!is_last_exp(exp)) {
if (eval(car(exp), env) != False) {
exp = cdr(exp);
}
else {
return False;
}
}
return car(exp);
}

/** or **/
else if (is_primitive_syntax(exp, or_symbol)) {
error("or not implemented yet");
object *result;
exp = cdr(exp);
while (exp != the_empty_list) {
result = eval(car(exp), env);
if (result == False) {
exp = cdr(exp);
}
else {
return result;
}
}
return False;
}

/** apply **/
Expand Down
24 changes: 24 additions & 0 deletions unit_test.lispy
Expand Up @@ -296,6 +296,30 @@
)


;; and
;;_________________________;;

(test
(and 1 2 3)
>>> 3
(and 1 False 2)
>>> False
)


;; or
;;_________________________;;

(test
(or 1 2)
>>> 1
(or False 2)
>>> 2
(or False False)
>>> False
)


;; apply
;;_________________________;;

Expand Down

0 comments on commit 6678871

Please sign in to comment.