diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-11-20 06:22:50 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-11-20 16:17:20 -0800 |
commit | 56383bfeeb21fe07a6d1fd17470148f72a2db7b1 (patch) | |
tree | fbc7bae573e12de7af2fc05f6b633228fb0d2938 | |
parent | 2f8d42ce8308fa4668213e8410d5abb204b0e712 (diff) | |
download | txr-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.c | 9 | ||||
-rw-r--r-- | txr.1 | 14 |
2 files changed, 17 insertions, 6 deletions
@@ -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) @@ -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 ) |