Up: Variable Initializations   [Contents][Index]


15.25.9.1 with

with var [type-spec] [= expr] {and var [type-spec] [= expr]}*
with

The ‘with’ construct initializes variables that are local to a loop. The variables are initialized one time only.

If the optional ‘type-spec’ argument is specified for any variable var, but there is no related expression expr to be evaluated, var is initialized to an appropriate default value for its data type. For example, for the data types ‘t’, ‘number’, and ‘float’, the default values are nil, 0, and 0.0, respectively. It is an error to specify a ‘type-spec’ argument for var if the related expression returns a value that is not of the specified type.

and

The optional ‘and’ clause forces parallel rather than sequential initializations.

Examples

;;; These bindings occur in sequence.
(loop with a = 1
      with b = (+ a 2)
      with c = (+ b 3)
      with d = (+ c 4)
      return (list a b c d))
;;; These bindings occur in parallel.
(setq a 5 b 10 c 1729)
(loop with a = 1
       and b = (+ a 2)
       and c = (+ b 3)
       and d = (+ c 4)
      return (list a b c d))
;;; This example shows a shorthand way to declare
;;; local variables that are of different types.
(loop with (a b c) (float integer float)
      return (format nil "~A ~A ~A" a b c))
;;; This example shows a shorthand way to declare
;;; local variables that are of the same type.
(loop with (a b c) float
      return (format nil "~A ~A ~A" a b c))

Up: Variable Initializations   [Contents][Index]