From a4fe85e6df2e308241984294a3d35353d7cc083a Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 12 Jan 2022 07:04:03 -0800 Subject: New macros: each-true, some-true, each-false, some-false. * lisplib.c (arith_each_set_entries): Trigger autoload on new symbols. * stdilb/arith-each.tl (sys:arith-each): Generalize macro to handle short-circuiting logical operations. The op-iv parameter, which is a cons, is spread into two op and iv parameter. One new argument appears, short-circ. This specifies a code for short-circuiting behavior: t means iteration continues while the result is true; nil means it continues while it is nil, and + means iteration continues while the accumulator is nonzero. A new convention is in effect: the operator has to be specified as a list in order to request accumulating behavior, e.g (+) or (*). Otherwise the operator specifies a predicate that is applied to the forms, without taking into account the prior value. (sum-each, sum-each*, mul-each, mul-each*): Spread the op-iv arguments. Wrap the op argument in a list to request accumulation. In the case of mul-each and mul-each*, specify + for the short-circ argument, which means that iteration stops when the accumulator becomes zerop. sum-each and sum-each* specify : for the short-circ argument which is unrecognized, and so ther is no short-circuiting behavior. (each-true, some-true, each-false, some-false): New macros. * tests/016/arith.tl: New tests. * txr.1: Documented new macros and added note about possible short-circuiting in mul-each and mul-each*. * stdlib/doc-syms.tl: Updated. --- lisplib.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lisplib.c') diff --git a/lisplib.c b/lisplib.c index bf88d921..80c8dc59 100644 --- a/lisplib.c +++ b/lisplib.c @@ -848,6 +848,7 @@ static val arith_each_set_entries(val dlt, val fun) { val name[] = { lit("sum-each"), lit("mul-each"), lit("sum-each*"), lit("mul-each*"), + lit("each-true"), lit("some-true"), lit("each-false"), lit("some-false"), nil }; set_dlt_entries(dlt, name, fun); -- cgit v1.2.3