Skip to content

Commit

Permalink
Added support for lists to < and >
Browse files Browse the repository at this point in the history
  • Loading branch information
ellamental committed Sep 10, 2010
1 parent a4bd54c commit 7cc4bce
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
48 changes: 45 additions & 3 deletions lispy.c
Expand Up @@ -1968,9 +1968,30 @@ object *h_greater_than(object *obj_1, object *obj_2) {
}

else if (obj_1->type == PAIR) {
error("> on pairs not implemented yet");
if (h_length(obj_1)->data.fixnum == h_length(obj_2)->data.fixnum) {
while (obj_1 != the_empty_list) {
if (h_equalp(car(obj_1), car(obj_2)) == True) {
obj_1 = cdr(obj_1);
obj_2 = cdr(obj_2);
}
else if (h_greater_than(car(obj_1), car(obj_2)) == True) {
return True;
}
else {
return False;
}
}
return False;
}

else if (h_length(obj_1)->data.fixnum > h_length(obj_2)->data.fixnum) {
return True;
}
else {
return False;
}
}

else if (obj_1->type == VECTOR) {
error("> on vectors not implemented yet");
}
Expand Down Expand Up @@ -2023,7 +2044,28 @@ object *h_less_than(object *obj_1, object *obj_2) {
}

else if (obj_1->type == PAIR) {
error("< on pairs not implemented yet");
if (h_length(obj_1)->data.fixnum == h_length(obj_2)->data.fixnum) {
while (obj_1 != the_empty_list) {
if (h_equalp(car(obj_1), car(obj_2)) == True) {
obj_1 = cdr(obj_1);
obj_2 = cdr(obj_2);
}
else if (h_less_than(car(obj_1), car(obj_2)) == True) {
return True;
}
else {
return False;
}
}
return False;
}

else if (h_length(obj_1)->data.fixnum < h_length(obj_2)->data.fixnum) {
return True;
}
else {
return False;
}
}

else if (obj_1->type == VECTOR) {
Expand Down
19 changes: 19 additions & 0 deletions unit_test.lispy
Expand Up @@ -909,6 +909,15 @@
>>> True
(> 'b 'a)
>>> True
(> '(1 2 4) '(1 2 3))
>>> True
(> '(1 2 3 4) '(1 2 3))
>>> True

(> '(1 2) '(1 2 3))
>>> False
(> '(1 2 3) '(1 2 4))
>>> False
)


Expand All @@ -926,6 +935,16 @@
>>> True
(< 'a 'b)
>>> True

(< '(1 2 3) '(1 2 4))
>>> True
(< '(1 2) '(1 2 3))
>>> True

(< '(1 2 3) '(1 2))
>>> False
(< '(1 2 4) '(1 2 3))
>>> False
)


Expand Down

0 comments on commit 7cc4bce

Please sign in to comment.