Wednesday, 15 April 2015

common lisp - Proclaim, declaim, declare -



common lisp - Proclaim, declaim, declare -

can please explain differences between 3 symbols proclaim, declaim , declare? thanks!

they symbols, not keywords.

proclaim names function making global declarations. should utilize declaim instead whenever possible.

declaim names macro making global declarations (like proclaim) effective @ compile-time.

declare symbol (i.g., not name function, macro, or special operator) making local declarations in origin of some forms.

so, first 2 impact global environment , lastly 1 local.

declaim preferable on proclaim because has immediate effect in compilation environment:

although execution of proclaim form has effects might impact compilation, compiler not create effort recognize , specially process proclaim forms. proclamation such following, if top level form, not have effect until executed:

(proclaim '(special *x*))

if compile time side effects desired, eval-when may useful. example:

(eval-when (:execute :compile-toplevel :load-toplevel) (proclaim '(special *x*)))

in such cases, however, preferrable utilize declaim purpose.

i.e., if code is

(proclaim '(special *x*)) (defun foo () (print *x*))

the compiler complain foo reads unknown special variable *x*, while

(declaim (special *x*)) (defun foo () (print *x*))

will cause no warnings.

common-lisp

No comments:

Post a Comment