Next: , Previous: , Up: Value Accumulation   [Contents][Index]


15.25.8.3 count - counting

count expr [into var] [type-spec]
counting expr [into var] [type-spec]
count
  • construct counts the number of times that the specified expression has a non-nil value.
var
  • accumulates the number of occurrences; if var is specified, the loop does not return the final count automatically. The var argument is bound as if by the construct ‘with’.
  • If ‘intovar is used, the optional ‘type-spec’ argument specifies a data type for var. If there is no ‘into’ variable, the optional ‘type-spec’ argument applies to the internal variable that is keeping the count. In either case it is an error to specify a non-numeric data type. The default type is implementation-dependent, but it must be a subtype of (or integer float).

Examples

;;; Sum the elements of a list.

(loop for i fixnum in '(1 2 3 4 5)
      sum i)
;;; Sum a function of elements of a list.

(setq series
      '(1.2 4.3 5.7))

(loop for v in series
      sum (* 2.0 v))