summaryrefslogtreecommitdiffstats
path: root/txr.1
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-02-02 18:52:48 -0800
committerKaz Kylheku <kaz@kylheku.com>2019-02-02 18:52:48 -0800
commitee93befb6473258ef880b5d4175487a4d901fb5e (patch)
tree322dc867de94b8f9aca85d6462234bdf600d34d0 /txr.1
parentc9cab7138636c6c1d6e47f8d1a4053bec2dd0ad4 (diff)
downloadtxr-ee93befb6473258ef880b5d4175487a4d901fb5e.tar.gz
txr-ee93befb6473258ef880b5d4175487a4d901fb5e.tar.bz2
txr-ee93befb6473258ef880b5d4175487a4d901fb5e.zip
sum and prod take keyfun argument.
* eval.c (eval_init): Adjust registrations of sum and prod to be binary functions with an optional argument. * lib.c (nary_op_keyfun, sumv, prodv): New static functions. (sum, prod): Implement optional keyfun argument via sumv and prodv helpers. * lib.h (sum, prod): Declarations updated. * txr.1: Documentation updated.
Diffstat (limited to 'txr.1')
-rw-r--r--txr.136
1 files changed, 23 insertions, 13 deletions
diff --git a/txr.1 b/txr.1
index cdcf22d6..e3f7ba46 100644
--- a/txr.1
+++ b/txr.1
@@ -35172,34 +35172,46 @@ value of the last division is returned.
.coNP Functions @ sum and @ prod
.synb
-.mets (sum << num-sequence )
-.mets (prod << num-sequence )
+.mets (sum < sequence <> [ keyfun ])
+.mets (prod < sequence <> [ keyfun ])
.syne
.desc
The
.code sum
and
.code prod
-functions operate on a single argument
-.metn num-sequence ,
-which is a sequence of numbers.
+functions operate on an effective sequence of numbers derived from
+.metn sequence .
+
+If the
+.meta keyfun
+argument is omitted, then the effective sequence is the
+.meta sequence
+argument itself. Otherwise, the effective sequence is understood to be
+a projection mapping of the elements of
+.meta sequence
+through
+.meta keyfun
+as would be calculated by the
+.cblk
+.meti (mapcar < keyfun << sequence )
+.cble
+expression.
The
.code sum
function returns the left-associative sum of the elements of
-.meta num-sequence
-calculated as if using the
+the effective sequence calculated as if using the
.code +
function. Similarly, the
.code prod
function calculates the left-associative product of the elements of
-.metn num-sequence ,
-as if using the
+the sequence as if using the
.code *
function.
If
-.meta num-sequence
+.meta sequence
is empty then
.code sum
returns
@@ -35209,9 +35221,7 @@ and
returns
.codn 1 .
-If
-.meta num-sequence
-contains one number, then both functions
+If the effective sequence contains one number, then both functions
return that number.
.coNP Functions @ wrap and @ wrap*