REDUCE

15.6 Constant Declaration

(define-constant NAME:id VALUE:any): any macro
The identifier NAME is declared a constant and its valuecell is set to VALUE. This provides a means for informing the compiler that the value of an id is constant. If a constant id is used in such a way that during evaluation its value would be accessed the compiler can then simply replace the id by its value. It is possible to use an id which has been declared a constant as a local variable within a prog or as a parameter name. It is possible to redefine the value of a constant.

Request to set constant NAME to a different value.

(constant? NAME:id): boolean expr
Returns t if NAME has been declared a constant with define-constant, otherwise nil.

The compiler attempts to replace function applications by the corresponding value whenever each of the arguments is either constant or an application which may be replaced by its value. The following is a list of all functions whose application may be evaluated during compilation. Clearly some functions like cons cannot be evaluated at compile time.

// /= < << <= = > >= >> ^ | ~ ~=

abs aconc acos acosd acot acotd acsc acscd add1 alphanumbericp alphap asec asecd asin asind ass assoc atan atan2 atan2d atand atom atsoc

bldmsg bothcasep

car cdr ceiling char-downcase char-equal char-font char- greaterp char-int char-lessp char-upcase char< char= char> constantp cos cosd cot cotd csc cscd

degreestodms degreestoradians difference digit digit-char digitp divide dmstodegrees dmstoradians

eq eqcar eqn eqstr equal expt

factorial fix fixp float floatp floor

geq getv

land lastcar lastpair length leq lessp list lnot log log10 log2 lor lowercasep lshift lxor

max2 member memq min2 minus minusp mkquote mod

ne neq not nth null

onep

pairp plus2 pnth

radianstodegrees radianstodms recip remainder rest reserse round

sec secd sin sind size sqrt string-not-greaterp string-not- lessp string-repeat string-search string-search-equal string- search-from-string-search-from-equal string-size string-trim string-upcase string-upper-bound string< string<= string<> string= string> string>= stringp sub sub1 substring-equal substring=

tan tand times2

upbv uppercasep

vector-empty? vector-fetch vector-size vector-upper-bound vector2l ist vector 2string vectorp

There is another facility in PSL for defining constants. You are encouraged to use the function define-constant. The following two functions are documented here for completeness.

(defconst [U:id V:any]): undefined macro
Defconst provides for the definition and use of symbolic constants. Each U is defined to represent the corresponding value V. The value V is stored on the property list of U, not in the valuecell. The macro const is used to retrieve the value.

(const U:id): any macro
Const gives access to the value defined by the function defconst. The value will be evaluated.
    1 lisp> (defconst foo (add1 2))  
    (add1 2)  
    2 lisp> (const foo)  
    3