User Tools

Site Tools


ch2_1_defconstant

DEFCONSTANT

Define symbol in global scope as constant. Constant symbol cannot be overwritten by SETQ, and cannot be even used as local variable in LET.

DEFCONSTANT form needs two arguments, and can have one more optional description string. The first parameter must be a symbol. Symbols from base package (reserved) will not be allowed, but DEFCONSTANT can be used to overwrite the value of user-defined constant. Second argument is evaluated, and will be bound as the value for the constant. Third, optional argument is a description string.

>(defconstant eul 2.72 "euler's number")   ; defining new meaningful constant
EUL
 
>(defconstant pi 3.14)                     ; trying to redefine built-in PI
;Using base-package name for DEFCONSTANT. Not allowed.    ; it fails
NIL
 
>(defconstant eul 2.71828)                 ; redefine with better precision
EUL

See also: DEFPARAMETER, DEFVAR, SETQ

ch2_1_defconstant.txt · Last modified: 2022/02/25 00:36 by admin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki