summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/lib.c b/lib.c
index a48fb78a..fe8efbb6 100644
--- a/lib.c
+++ b/lib.c
@@ -664,26 +664,22 @@ loc term(loc head)
return head;
}
-loc lastcons(val list)
+val lastcons(val list)
{
- loc ret = nulloc;
-
+ val ret;
gc_hint(list);
- while (consp(cdr(list))) {
- ret = cdr_l(list);
- list = deref(ret);
- }
+ for (ret = nil; consp(list); list = cdr(list))
+ ret = list;
+
return ret;
}
val last(val seq, val n)
{
if (null_or_missing_p(n)) {
- if (listp(seq)) {
- loc p = lastcons(seq);
- return nullocp(p) ? seq : deref(p);
- }
+ if (listp(seq))
+ return lastcons(seq);
return sub(seq, negone, t);
} else {
if (listp(seq))