Common Lisp the Language, 2nd Edition


next up previous contents index
Next: Destructuring Up: Miscellaneous Features Previous: Miscellaneous Features

26.12.1. Data Types

change_begin
Many loop constructs take a type-spec argument that allows you to specify certain data types for loop variables. While it is not necessary to specify a data type for any variable, by doing so you ensure that the variable has a correctly typed initial value. The type declaration is made available to the compiler for more efficient loop expansion. In some implementations, fixnum and float declarations are especially useful; the compiler notices them and emits more efficient code.

The type-spec argument has the following syntax:

type-spec ::= of-type d-type-spec
d-type-spec ::= type-specifier | (d-type-spec . d-type-spec)
A type-specifier in this syntax can be any Common Lisp type specifier. The d-type-spec argument is used for destructuring, as described in section 26.12.2. If the d-type-spec argument consists solely of the types fixnum, float, t, or nil, the of-type keyword is optional. The of-type construct is optional in these cases to provide backward compatibility; thus the following two expressions are the same:

;;; This expression uses the old syntax for type specifiers. 
(loop for i fixnum upfrom 3 ...) 

;;; This expression uses the new syntax for type specifiers. (loop for i of-type fixnum upfrom 3 ...)


change_end


AI.Repository@cs.cmu.edu