summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--lib.c9
-rw-r--r--txr.114
2 files changed, 17 insertions, 6 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)
diff --git a/txr.1 b/txr.1
index 045d760e..4bb31634 100644
--- a/txr.1
+++ b/txr.1
@@ -14850,11 +14850,11 @@ See the relevant examples below.
.coNP Function @ last
.synb
-.mets (last << list )
+.mets (last << seq )
.syne
.desc
If
-.meta list
+.meta seq
is a nonempty proper or improper list, the
.code last
function
@@ -14863,13 +14863,21 @@ returns the last cons cell in the list: that cons cell whose
field is a terminating atom.
If
-.meta list
+.meta seq
is
.codn nil ,
then
.code nil
is returned.
+If
+.meta seq
+is a non-list sequence, then a one-element suffix of
+.code seq
+is returned, or an empty suffix if
+.code seq
+is an empty sequence.
+
.coNP Accessor @ nthcdr
.synb
.mets (nthcdr < index << list )