3.5 Function Definition

Functions in Standard LISP are global entities. To avoid function-variable naming clashes no variable may have the same name as a function.

DE(FNAME:id, PARAMS:id-list, FN:any):id noeval, nospread
 
The function FN with the formal parameter list PARAMS is added to the set of defined functions with the name FNAME. Any previous definitions of the function are lost. The function created is of type EXPR. If the !*COMP variable is non-NIL, the EXPR is first compiled. The name of the defined function is returned.
FEXPR PROCEDURE DE(U);

  PUTD(CAR U, ’EXPR, LIST(’LAMBDA, CADR U, CADDR U));

DF(FNAME:id, PARAM:id-list, FN:any):id noeval, nospread
 
The function FN with formal parameter PARAM is added to the set of defined functions with the name FNAME. Any previous definitions of the function are lost. The function created is of type FEXPR. If the !*COMP variable is T the FEXPR is first compiled. The name of the defined function is returned.
FEXPR PROCEDURE DF(U);

  PUTD(CAR U, ’FEXPR, LIST(’LAMBDA, CADR U, CADDR U));

DM(MNAME:id, PARAM:id-list, FN:any):id noeval, nospread
 
The macro FN with the formal parameter PARAM is added to the set of defined functions with the name MNAME. Any previous definitions of the function are overwritten. The function created is of type MACRO. The name of the macro is returned.
FEXPR PROCEDURE DM(U);

  PUTD(CAR U, ’MACRO, LIST(’LAMBDA, CADR U, CADDR U));

GETD(FNAME:any):{NIL, dotted-pair} eval, spread
 
If FNAME is not the name of a defined function, NIL is returned. If FNAME is a defined function then the dotted-pair

(TYPE:ftype . DEF:{function-pointer, lambda})

is returned.

PUTD(FNAME:id, TYPE:ftype, BODY:function):id eval, spread
 
Creates a function with name FNAME and definition BODY of type TYPE. If PUTD succeeds the name of the defined function is returned. The effect of PUTD is that GETD will return a dotted-pair with the functions type and definition. Likewise the GLOBALP predicate will return T when queried with the function name.

If the function FNAME has already been declared as a GLOBAL or FLUID variable the error:

***** FNAME is a non-local variable

occurs and the function will not be defined. If function FNAME already exists a warning message will appear:

*** FNAME redefined

The function defined by PUTD will be compiled before definition if the !*COMP global variable is non-NIL.

REMD(FNAME:id):{NIL, dotted-pair} eval, spread
 
Removes the function named FNAME from the set of defined functions. Returns the (ftype . function) dotted-pair or NIL as does GETD. The global/function attribute of FNAME is removed and the name may be used subsequently as a variable.