Special Form Entry: DEFUN-Q

← Prev | ↑ Chapter | Next → | Index | Symbols

Special Form Entry: DEFUN-Q

Name

defun-q

Class

Special Form

Syntax

(defun-q sym ([arguments] [/ variables ...]) expr ...)

Description

Defines a function in a backward-compatible representation that can be accessed as a list structure.

Historically, older non-compiled AutoLISP implementations represented defun definitions as list structure. Autodesk documents that this changed in AutoCAD 2000. After that change, ordinary defun definitions were no longer safely manipulable as lists.

defun-q exists specifically to preserve compatibility with older code that:

  • inspects function definitions as list data,
  • appends to or rewrites function bodies as lists,
  • expects to retrieve a function definition structurally rather than only call it.

Accordingly, defun-q is not just another spelling of defun. It defines a callable function while also preserving a list-form definition that can be retrieved and manipulated by compatibility utilities such as defun-q-list-ref and defun-q-list-set.

Autodesk explicitly says that defun-q is provided strictly for backward compatibility and should not be used for other purposes.

Evaluation Rules

  • the defining form establishes a global function binding
  • the defined function is callable in the usual way
  • the definition is also retained in list form for reflective compatibility operations

Return Values

Returns the function name.

Side Effects

  • defines or redefines a global function
  • stores a list-structured representation of the definition for later access by compatibility functions

Compatibility

Autodesk documents duplicate names as tolerated with first occurrence used and later duplicates ignored.

An ordinary defun definition should not be assumed to be accessible as list structure in modern AutoCAD semantics. Attempting to use a defun function as a list is documented to produce an error, with Autodesk explicitly suggesting defun-q instead for old compatibility patterns.

Examples

  • define a compatibility-visible function:
    • (defun-q my-startup (x) (print (list x)))
  • retrieve its stored list structure:
    • (defun-q-list-ref 'my-startup) => ((X) (PRINT (LIST X)))
  • older code patterns that splice or append function bodies are the intended use case for defun-q

Notes

Conceptually, defun-q separates two concerns that were historically conflated:

  • defining a callable function,
  • treating the function definition as ordinary list data.

Modern defun covers the first concern. defun-q exists only for the second, compatibility-driven concern.

Availability

  • AutoCAD 2026: documented (per Autodesk reference page).
  • BricsCAD V26: presumed compatible (no contradicting page found).
  • Status: AutoCAD documented; BricsCAD presumed-both pending Phase 4 verification.