3.2 Making declarations

3.2.4 RESTRICTIVE-FTYPE declarations

Arestrictive-ftype declaration specifies both the argument types and the result types of a set of functions. While anftype declaration conditionally restricts the value type of a function, arestrictive-ftype declaration unconditionally restricts both the argument types and the value type of a function. It is an error if the arguments to the function are not of the specified type, and the Compiler might produce unexpected results.

Therestrictive-ftype has the following form:

(declare (restrictive-ftype type function-name-1 function-name-2 ...))
The following proclamation declares that the function times will only accept two fixnum arguments and will always return a fixnum value:

(defun times (x y) (* x y))
(proclaim '(restrictive-ftype (function (fixnum fixnum) fixnum) times))
Thus, in the following code, all of the arithmetic operators can be compiled as fixnum operators without requiring any additional declarations:

(defun do-some-arithmetic (i j)
  (declare (fixnum i j))
  (times (+ (times (* i j) (+ i j)) j) i))


The Advanced User's Guide - 9 SEP 1996

Generated with Harlequin WebMaker