From 7e36a3f2a6501a0bc6d24836610746f59427b496 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 23 Sep 2021 06:21:30 -0700 Subject: New variants of each operator for sum and product. * lisplib.c (arith_each_instantiate, arith_each_set_entries): New functions. (each_prod_set_entries): Add sum-each-prod, sum-each-prod*, mul-each-prod and mul-each-prod* as autoload triggers for each-prod.tl, where those macros are now defined. (lisplib_init): Register autoloading of arith-each.tl via the two new functions. * stdlib/arith-each.tl: New file. * stdlib/each-prod.tl (sys:expand-each-prod*): Handle sum-each-prod* and mul-each-prod* in the same way, by mapping to their parallel binding counterparts. (sys:expand-arith-each-prod): New function. (sym-each-prod, mul-each-prod, sum-each-prod*, mul-each-prod*): New macros. * tests/016/arith.tl: New tests. * txr.1: Documented. * stdlib/doc-syms.tl: Updated. --- lisplib.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lisplib.c') diff --git a/lisplib.c b/lisplib.c index 3a5beb78..17485812 100644 --- a/lisplib.c +++ b/lisplib.c @@ -835,6 +835,23 @@ static val copy_file_set_entries(val dlt, val fun) return nil; } +static val arith_each_instantiate(val set_fun) +{ + funcall1(set_fun, nil); + load(scat2(stdlib_path, lit("arith-each"))); + return nil; +} + +static val arith_each_set_entries(val dlt, val fun) +{ + val name[] = { + lit("sum-each"), lit("mul-each"), lit("sum-each*"), lit("mul-each*"), + nil + }; + set_dlt_entries(dlt, name, fun); + return nil; +} + static val each_prod_instantiate(val set_fun) { funcall1(set_fun, nil); @@ -846,7 +863,9 @@ static val each_prod_set_entries(val dlt, val fun) { val name[] = { lit("each-prod"), lit("collect-each-prod"), lit("append-each-prod"), + lit("sum-each-prod"), lit("mul-each-prod"), lit("each-prod*"), lit("collect-each-prod*"), lit("append-each-prod*"), + lit("sum-each-prod*"), lit("mul-each-prod*"), nil }; set_dlt_entries(dlt, name, fun); @@ -1009,6 +1028,7 @@ void lisplib_init(void) dlt_register(dl_table, save_exe_instantiate, save_exe_set_entries); dlt_register(dl_table, defset_instantiate, defset_set_entries); dlt_register(dl_table, copy_file_instantiate, copy_file_set_entries); + dlt_register(dl_table, arith_each_instantiate, arith_each_set_entries); dlt_register(dl_table, each_prod_instantiate, each_prod_set_entries); dlt_register(dl_table, quips_instantiate, quips_set_entries); dlt_register(dl_table, match_instantiate, match_set_entries); -- cgit v1.2.3