Skip to main content

compiler-macro-function

compiler-macro-function Accessor

Syntax:

compiler-macro-function name &optional environment → function

(setf (compiler-macro-function name &optional environment**)** new-function**)**

Arguments and Values:

name—a function name.

environment—an environment object.

function, new-function—a compiler macro function, or nil.

Description:

Accesses the compiler macro function named name, if any, in the environment.

A value of nil denotes the absence of a compiler macro function named name.

Exceptional Situations:

The consequences are undefined if environment is non-nil in a use of setf of compiler-macro-function.

See Also:

define-compiler-macro, Section 3.2.2.1 (Compiler Macros)

Expanded Reference: compiler-macro-function

Checking for a Compiler Macro

compiler-macro-function returns the compiler macro function associated with a name, or nil if there is none.

(defun my-fn (x) x)
=> MY-FN

(compiler-macro-function 'my-fn)
=> NIL

(define-compiler-macro my-fn (&whole form x)
(if (constantp x) x form))
=> MY-FN

(compiler-macro-function 'my-fn)
==> #<FUNCTION ...>

Invoking the Compiler Macro Function Directly

The returned function takes two arguments: the form and an environment object.

(funcall (compiler-macro-function 'my-fn) '(my-fn 42) nil)
;; => 42

(funcall (compiler-macro-function 'my-fn) '(my-fn x) nil)
;; => (MY-FN X)

Removing a Compiler Macro with setf

(setf (compiler-macro-function 'my-fn) nil)
=> NIL

(compiler-macro-function 'my-fn)
=> NIL