diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-11-16 06:45:13 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-11-20 16:17:18 -0800 |
commit | bc85ec12271ecc273cb36e7ef35d071c364e46ab (patch) | |
tree | f47cf7678525f2b2f3f56dbcf0a74e967b377bad | |
parent | 4d2ab06904fd69c0fc7ba3c5237127726ab5c98b (diff) | |
download | txr-bc85ec12271ecc273cb36e7ef35d071c364e46ab.tar.gz txr-bc85ec12271ecc273cb36e7ef35d071c364e46ab.tar.bz2 txr-bc85ec12271ecc273cb36e7ef35d071c364e46ab.zip |
Provide butlast function.
* eval.c (eval_init): Registered butlast intrinsic.
* lib.c (butlast): New function.
* lib.h (butlast): Declared.
* txr.1: Documented butlast.
-rw-r--r-- | eval.c | 1 | ||||
-rw-r--r-- | lib.c | 5 | ||||
-rw-r--r-- | lib.h | 1 | ||||
-rw-r--r-- | txr.1 | 24 |
4 files changed, 31 insertions, 0 deletions
@@ -4471,6 +4471,7 @@ void eval_init(void) reg_fun(intern(lit("reverse"), user_package), func_n1(reverse)); reg_fun(intern(lit("ldiff"), user_package), func_n2(ldiff)); reg_fun(intern(lit("last"), user_package), func_n1(last)); + reg_fun(intern(lit("butlast"), user_package), func_n1(butlast)); reg_fun(intern(lit("nthcdr"), user_package), func_n2(nthcdr)); reg_fun(intern(lit("flatten"), user_package), func_n1(flatten)); reg_fun(intern(lit("flatten*"), user_package), func_n1(lazy_flatten)); @@ -7396,6 +7396,11 @@ val dwim_del(val seq, val ind_range) } } +val butlast(val seq) +{ + return sub(seq, zero, negone); +} + val update(val seq, val fun) { switch (type(seq)) { @@ -905,6 +905,7 @@ val ref(val seq, val ind); val refset(val seq, val ind, val newval); val dwim_set(val seq, val ind_range, val newval); val dwim_del(val seq, val ind_range); +val butlast(val seq); val replace(val seq, val items, val from, val to); val update(val seq, val fun); val search(val seq, val key, val from, val to); @@ -20103,6 +20103,30 @@ is returned, which may be .meta sequence itself or a copy. +.coNP Function @ butlast +.synb +.mets (butlast << sequence ) +.syne +.desc +The +.code butlast +function returns the prefix of +.meta sequence +consisting of a copy of it, with the last item omitted. +If +.meta sequence +is empty, an empty sequence is returned. + +Dialect note: the Common Lisp function +.code nbutlast +is not provided. The \*(TL +.code take +function provides the same functionality for lists (only with the +arguments reversed relative to +.codn nbutlast ), +and additionally provides lazy semantics, and works with vectors +and strings. + .coNP Function @ search .synb .mets (search < haystack < needle >> [ testfun <> [ keyfun ]) |