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


15.25.8.4 maximize - maximizing - minimize - minimizing

maximize expr [into var] [type-spec]
maximizing expr [into var] [type-spec]
minimize expr [into var] [type-spec]
minimizing expr [into var] [type-spec]
maximize
  • construct compares the value of the specified expression obtained during the first iteration with values obtained in successive iterations.
  • The maximum value encountered is determined and returned.
  • If the loop never executes the body, the returned value is not meaningful.
minimize
  • construct is similar to maximize; it determines and returns the minimum value.
var
  • accumulates the maximum or minimum value;
  • if var is specified, the loop does not return the maximum or minimum automatically.
  • The var argument is bound as if by the construct ‘with’.
  • If ‘into’ var 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 intermediate result. 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

(loop for i in '(2 1 5 3 4)
      maximize i)
(loop for i in '(2 1 5 3 4)
      minimize i)
;;; In this example, FIXNUM applies to the internal
;;; variable that holds the maximum value.

(setq series '(1.2 4.3 5.7))

(loop for v in series
      maximize (round v) fixnum)
;;; In this example, FIXNUM applies to the variable RESULT.

(loop for v float in series
      minimize (round v) into result fixnum
      finally (return result))

Previous: count - counting, Up: Value Accumulation   [Contents][Index]