Next: , Previous: , Up: loops comprehensions   [Index]


1.16.2.5 Arithmetic accumulator loops

Syntax: sum-ec ?qualifier ... expression

The sum of all values of expression. Think of it as:

(apply + (list-ec ?qualifier ... expression))

Examples:

(sum-ec                 ;no qualifiers
  1)
⇒ 1

(sum-ec (:range i 0)
  i)
⇒ 0

(sum-ec (:range i 1)
  i)
⇒ 0

(sum-ec (:range i 2)
  i)
⇒ 1

(sum-ec (:range i 3)
  i)
⇒ 3
Syntax: product-ec ?qualifier ... expression

The product of all values of expression. Think of it as:

(apply * (list-ec ?qualifier ... expression))

Examples:

(product-ec             ;no qualifiers
  1)
⇒ 1

(product-ec (:range i 1 0)      ;i from 1 to 1
  i)
⇒ 1

(product-ec (:range i 1 1)      ;loop zero times
  i)
⇒ 1

(product-ec (:range i 9 9)      ;loop zero times
  i)
⇒ 1

(product-ec (:range i 1 2)      ;i from 1 to 1
  i)
⇒ 1

(product-ec (:range i 1 3)      ;i from 1 to 2
  i)
⇒ 2

(product-ec (:range i 1 4)      ;i from 1 to 3
  i)
⇒ 6
Syntax: min-ec ?qualifier ... expression
Syntax: max-ec ?qualifier ... expression

The minimum and maximum of all values of expression. The sequence of values must be non-empty. Think of these as

(apply min (list-ec ?qualifier ... expression))
(apply max (list-ec ?qualifier ... expression))

If we want to return a default value in case the sequence is empty we may want to consider:

(fold3-ec 'infinity ?qualifier ... expression min min)