Global generation
This commit is contained in:
26
src/list.c
26
src/list.c
@ -16,6 +16,14 @@ intptr_t list_length(LispVal *list) {
|
||||
return length;
|
||||
}
|
||||
|
||||
bool list_length_eq(LispVal *list, intptr_t size) {
|
||||
assert(LISTP(list));
|
||||
while (size-- && CONSP(list)) {
|
||||
list = XCDR(list);
|
||||
}
|
||||
return size == 0;
|
||||
}
|
||||
|
||||
DEFUN(cons, "cons", (LispVal * car, LispVal *cdr), "(car cdr)",
|
||||
"Construct a new cons object from CAR and CDR.") {
|
||||
return CONS(car, cdr);
|
||||
@ -25,3 +33,21 @@ DEFUN(length, "length", (LispVal * list), "(list)", "") {
|
||||
// TODO type check
|
||||
return MAKE_FIXNUM(list_length(list));
|
||||
}
|
||||
|
||||
DEFUN(length_eq, "length=", (LispVal * list, LispVal *length), "(list length)",
|
||||
"Return non-nil if LIST's length is LENGTH.") {
|
||||
// TODO type check
|
||||
return list_length_eq(list, XFIXNUM(length)) ? Qt : Qnil;
|
||||
}
|
||||
|
||||
DEFUN(nreverse, "nreverse", (LispVal * list), "(list)", "") {
|
||||
// TODO type checking
|
||||
LispVal *rev = Qnil;
|
||||
while (!NILP(list)) {
|
||||
LispVal *next = XCDR(list);
|
||||
RPLACD(list, rev);
|
||||
rev = list;
|
||||
list = next;
|
||||
}
|
||||
return rev;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user