Declarations allow users to provide extra information to Lisp about variables, functions, and forms. Declarations are optional but can affect interpretation. The declare construct embeds declarations and they are valid at the start of certain special forms and lambda expressions. Common declaration specifiers include type, special, ftype, inline, and notinline to provide type or implementation information. Declarations have scope within forms and for variable bindings.
2. Declarations Declarations allow the user to specify extra information about the program to Lisp system. Declarations are truly optional but special declarations do effect the interpretation of the variable bindings and references and so must be specified wherever necessary. Declarations are one of the good ways to add documentation to the program.
4. Declaration syntax declare construct is used to embed declarations within the executable code. A declare form is known as the declaration. A declaration may occur only at the beginning of the bodies of the certain special forms. declare {decl-spec}*
6. Variable bindings appear only to the bindings made by the form at the head of whose body they appear. (defun foo (x) (declare (type float x)).. (let (( x’a)) …) ….) The type declaration applies only to the outer binding of the x and not to the binding made in the let. The scope of the declaration always includes the body forms, as well as any “stepper” or “result” forms, of the special forms or lambda-expressions. If the declaration applies to a name binding, then the scope of declaration also includes the scope of the name binding.
7. locally {declaration}* {form}* This macro is used to make local pervasive declarations where desired. This construct does not bind any variables. Special declaration may be used with lacally to pervasively affect references to, rather than bindings of, variables. The function proclaim takes a decl-spec as its argument and puts it into effect globally.
8. proclaim decl-spec The proclaim takes decl-spec as the argument and puts it into effect globally. Ex: (proclaim ‘(type float tolerance)) specifies that the dynamic value of the tolerance should always be a floating-point number. A proclaim takes special decl-spec as applying to all bindings as well as to all references of the mentioned variables. This macro is syntactically like declare and semantically like proclaim. It is an executable form and may be used anywhere proclaim may be called. declaim {decl-spec}*
9. Declaration specifiers List of valid declaration specifiers for use in declare. (special var1 var2….) specifies that all of the variables named are to be considered special. (type var1, var2,…) affects only variable bindings and specifies that the variables mentioned will take on values only of the specified type.
10. (ftype type function-name-1, function-name-2,…) specifies that the named functions will be of the function type type. Ex: (declare (ftype(function (integer list) t) nth) (ftype (function (number) float) sin cos)) To extend ftype declaration specifiers to accept any function-name, one may write (declaim (ftype (function (list) t) (setf cadr)))
11. (inline function1, function2,…)specifies that it is desirable for the compiler to open code calls to the specified functions. The compiler is free to ignore this declaration. (notinline function1, function2,…)specifies that it is undesirable for the compiler to compile the specified functions inline. This declaration is pervasive and the compiler is not free to ignore this declaration. (ignore var1,var2,….) affects only variable bindings and specifies that the bindings of the specified variables are never used. (optimize (quality1 value1) (quality2 vale2)…) advises compiler that each quality must be given attention according to the specified corresponding value.
12. (declaration name1, name2,…) advises the compiler that each namej is a valid but non-standard declaration name. The is kind of declaration may be used only as a proclamation. Ex: (proclaim ‘(declaration author target-language target-machine)) (proclaim ‘(target-language ada)) (proclaim ‘(target-machine IBM-650)) (defun strangep(x) (declare (author “Harry Tweeker”)) (member x’(strange weird odd peculiar)))
13. Type declarations for forms The special form is defined to declare the type of value held by a bound variable. (the type form)the type of value means the type of value of is declared to be of type type. the value-type formthe form is evaluated and whatever it produces is returned by the form, it is an error if what is returned by the form does not confirm to the data-type specified by value-type.
14. Examples: (the string (copy-seq x)) the result will be a string. (the integer (+ x 3)) the result of + will be an integer. (+ (the integer x) 3)the value of x will be an integer.
15. Visit more self help tutorials Pick a tutorial of your choice and browse through it at your own pace. The tutorials section is free, self-guiding and will not involve any additional support. Visit us at www.dataminingtools.net