summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eval.c1
-rw-r--r--lib.c5
-rw-r--r--lib.h1
-rw-r--r--txr.124
4 files changed, 31 insertions, 0 deletions
diff --git a/eval.c b/eval.c
index fd5a720f..b1bb0d17 100644
--- a/eval.c
+++ b/eval.c
@@ -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));
diff --git a/lib.c b/lib.c
index 09e85693..580b2c2c 100644
--- a/lib.c
+++ b/lib.c
@@ -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)) {
diff --git a/lib.h b/lib.h
index 153492d9..3b10ce6d 100644
--- a/lib.h
+++ b/lib.h
@@ -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);
diff --git a/txr.1 b/txr.1
index 281bc167..dbb819d9 100644
--- a/txr.1
+++ b/txr.1
@@ -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 ])