summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eval.c1
-rw-r--r--lib.c19
-rw-r--r--lib.h1
-rw-r--r--stdlib/doc-syms.tl1
-rw-r--r--tests/012/seq.tl8
-rw-r--r--txr.157
6 files changed, 87 insertions, 0 deletions
diff --git a/eval.c b/eval.c
index af5c1505..b3a6e869 100644
--- a/eval.c
+++ b/eval.c
@@ -7277,6 +7277,7 @@ void eval_init(void)
reg_fun(intern(lit("copy-cons"), user_package), func_n1(copy_cons));
reg_fun(intern(lit("copy-tree"), user_package), func_n1(copy_tree));
reg_fun(intern(lit("copy-alist"), user_package), func_n1(copy_alist));
+ reg_fun(intern(lit("pairlis"), user_package), func_n3o(pairlis, 2));
reg_fun(intern(lit("prop"), user_package), func_n2(getplist));
reg_fun(intern(lit("memp"), user_package), func_n2(memp));
reg_fun(intern(lit("plist-to-alist"), user_package), func_n1(plist_to_alist));
diff --git a/lib.c b/lib.c
index cce37b3a..a82bdea7 100644
--- a/lib.c
+++ b/lib.c
@@ -10103,6 +10103,25 @@ val copy_alist(val list)
return out;
}
+val pairlis(val keys, val values, val alist_in)
+{
+ val self = lit("pairlis");
+ val alist = default_null_arg(alist_in);
+ seq_iter_t sik, siv;
+ val key, value;
+ list_collect_decl (out, ptail);
+
+ seq_iter_init(self, &sik, keys);
+ seq_iter_init(self, &siv, values);
+
+ while (seq_get(&sik, &key) && seq_get(&siv, &value))
+ ptail = list_collect(ptail, cons(key, value));
+
+ list_collect_nconc(ptail, alist);
+
+ return out;
+}
+
val mapcar_listout(val fun, val seq)
{
val self = lit("mapcar");
diff --git a/lib.h b/lib.h
index 2d7650ff..b2cadfac 100644
--- a/lib.h
+++ b/lib.h
@@ -1164,6 +1164,7 @@ val alist_nremove1(val list, val key);
val copy_cons(val cons);
val copy_tree(val tree);
val copy_alist(val list);
+val pairlis(val keys, val values, val alist_in);
val mapcar_listout(val fun, val seq);
val mapcar(val fun, val seq);
val mapcon(val fun, val list);
diff --git a/stdlib/doc-syms.tl b/stdlib/doc-syms.tl
index 6be397ea..63894b85 100644
--- a/stdlib/doc-syms.tl
+++ b/stdlib/doc-syms.tl
@@ -1399,6 +1399,7 @@
("package-symbols" "N-03AF0206")
("packagep" "N-007A478F")
("pad" "N-0247F5FA")
+ ("pairlis" "N-02EA9B54")
("parenb" "N-01B1B5DF")
("parmrk" "N-02391683")
("parodd" "N-01B1B5DF")
diff --git a/tests/012/seq.tl b/tests/012/seq.tl
index ed2e02b8..1bc45b55 100644
--- a/tests/012/seq.tl
+++ b/tests/012/seq.tl
@@ -437,3 +437,11 @@
(mtest
[subst "brown" "black" #("how" "now" "BROWN" "cow") : downcase-str] #("how" "now" "black" "cow")
[subst 5 0 '(1 2 3 4 5 6 7 8 9 10) <] (1 2 3 4 5 0 0 0 0 0))
+
+(mtest
+ (pairlis nil nil) nil
+ (pairlis "abc" #(1 2 3 4)) ((#\a . 1) (#\b . 2) (#\c . 3))
+ (pairlis "abcd" #(1 2 3)) ((#\a . 1) (#\b . 2) (#\c . 3))
+ (pairlis "" #(1 2 3)) nil
+ (pairlis "abcd" #()) nil
+ (pairlis '(1 2 3) '(a b c) '(4 5 6)) ((1 . a) (2 . b) (3 . c) 4 5 6))
diff --git a/txr.1 b/txr.1
index 76be9f33..46cfe27b 100644
--- a/txr.1
+++ b/txr.1
@@ -22710,6 +22710,63 @@ is produced as if by the
function applied to the corresponding
element of the input list.
+.coNP Function @ pairlis
+.synb
+.mets (pairlis < keys < values <> [ alist ])
+.syne
+.desc
+The
+.code pairlis
+function returns a association list consisting of pairs formed from
+the elements of
+.meta keys
+and
+.meta values
+prepended to the existing
+.metn alist .
+
+If an
+.meta alist
+argument is omitted, it defaults to
+.codn nil .
+
+Pairs of elements are formed by taking successive elements from the
+.meta keys
+and
+.meta values
+sequences in parallel.
+
+If the sequences are not of equal length, the excess elements from
+the longer sequence are ignored.
+
+The pairs appear in the resulting list in the original order in
+which their constituents appeared in
+.meta keys
+and
+.metn values .
+
+.TP* "Dialect Note:"
+The ANSI CL
+.code pairlis
+requires
+.meta key
+and
+.meta data
+to be lists, not sequences. The behavior of the ANSI CL
+.code pairlis
+is undefined of those lists are of different lengths. Finally, the elements are
+permitted to appear in either the original order or reverse order.
+
+.TP* Examples:
+
+.verb
+ (pairlis nil nil) -> nil
+ (pairlis "abc" #(1 2 3 4)) -> ((#\ea . 1) (#\eb . 2) (#\ec . 3))
+
+ (pairlis '(1 2 3) '(a b c) '((x . y) (z . w)))
+ -> ((1 . a) (2 . b) (3 . c) (x . y) (z . w))
+.brev
+
.SS* Property Lists
A
.IR "property list",