From 25e2779a39949a11ac597774aa4207d4d04a54d3 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 28 Jun 2020 11:47:13 -0700 Subject: New function: maprodo. maprodo is like maprod, but doesn't collect or return anything. It's the Cartesian product analog of mapdo. * eval.c (collect_nothing, maprodo): New static functions. (eval_init): Register maprodo intrinsic. * txr.1: Documented. --- eval.c | 12 ++++++++++++ txr.1 | 28 +++++++++++++++++++++------- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/eval.c b/eval.c index cd282da0..1d1b6cf0 100644 --- a/eval.c +++ b/eval.c @@ -5463,6 +5463,17 @@ val maprendv(val fun, struct args *lists) return prod_common(fun, lists, list_collect_append, mappendv); } +static loc collect_nothing(loc ptail, val obj) +{ + (void) obj; + return ptail; +} + +static val maprodo(val fun, struct args *lists) +{ + return prod_common(fun, lists, collect_nothing, mappendv); +} + static val symbol_value(val sym) { uses_or2; @@ -6535,6 +6546,7 @@ void eval_init(void) reg_fun(intern(lit("mapdo"), user_package), func_n1v(mapdov)); reg_fun(intern(lit("maprod"), user_package), func_n1v(maprodv)); reg_fun(intern(lit("maprend"), user_package), func_n1v(maprendv)); + reg_fun(intern(lit("maprodo"), user_package), func_n1v(maprodo)); reg_fun(intern(lit("window-map"), user_package), func_n4(window_map)); reg_fun(intern(lit("window-mappend"), user_package), func_n4(window_mappend)); reg_fun(intern(lit("window-mapdo"), user_package), func_n4(window_mapdo)); diff --git a/txr.1 b/txr.1 index 64d5a691..5a5c0017 100644 --- a/txr.1 +++ b/txr.1 @@ -32131,25 +32131,28 @@ and so doesn't return. -> (2 4) .brev -.coNP Functions @ maprod and @ maprend +.coNP Functions @, maprod @ maprend and @ maprodo .synb .mets (maprod < function << iterable *) .mets (maprend < function << iterable *) +.mets (maprodo < function << iterable *) .syne .desc The -.code maprod -and +.codn maprod , .code maprend +and +.code maprodo functions resemble -.code mapcar +.codn mapcar , +.code mappend and -.codn mappend , +.codn mapdo , respectively. When given no .meta iterable arguments or exactly one .meta iterable -argument, they behave exactly like those two functions. +argument, they behave exactly like those three functions. When two or more .meta iterable @@ -32157,7 +32160,9 @@ arguments are present, .code maprod differs from .code mapcar -in the following way. Whereas +in the following way, as do the remaining functions +from their aforementioned counterparts. +Whereas .code mapcar iterates over the .meta iterable @@ -32216,6 +32221,15 @@ and the final result is converted to the same kind of sequence as the leftmost .meta iterable if possible. +The +.code maprodo +function, like +.codn mapdo , +ignores the result of +.meta function +and returns +.codn nil . + The combination iteration gives priority to the rightmost .metn iterable , which means that the rightmost element of each generated tuple varies -- cgit v1.2.3