summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-11-20 06:22:50 -0800
committerKaz Kylheku <kaz@kylheku.com>2015-11-20 16:17:20 -0800
commit56383bfeeb21fe07a6d1fd17470148f72a2db7b1 (patch)
treefbc7bae573e12de7af2fc05f6b633228fb0d2938 /lib.c
parent2f8d42ce8308fa4668213e8410d5abb204b0e712 (diff)
downloadtxr-56383bfeeb21fe07a6d1fd17470148f72a2db7b1.tar.gz
txr-56383bfeeb21fe07a6d1fd17470148f72a2db7b1.tar.bz2
txr-56383bfeeb21fe07a6d1fd17470148f72a2db7b1.zip
last function becomes generic.
* lib.c (last): Handle non-list sequences via sub function. * txr.1: Updated description of last.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib.c b/lib.c
index 0dc1b543..d658f356 100644
--- a/lib.c
+++ b/lib.c
@@ -559,10 +559,13 @@ loc lastcons(val list)
return ret;
}
-val last(val list)
+val last(val seq)
{
- loc p = lastcons(list);
- return nullocp(p) ? list : deref(p);
+ if (listp(seq)) {
+ loc p = lastcons(seq);
+ return nullocp(p) ? seq : deref(p);
+ }
+ return sub(seq, negone, t);
}
val nthcdr(val pos, val list)