Telling AutoLISP Not to Evaluate an Expression

Besides specifying AutoLISP functions themselves, lists will be used for two key purposes in AutoCAD: specifying coordinates in space (“point” lists) or describing a specific AutoCAD entity (“entity definition” lists).

To explicitly type in a point list, a list of three real numbers, creates a problem: AutoLISP will try to evaluate the list as a function.

Command: (setq PT1 (1.0 2.0 0.0))
error: bad function

(1.0 2.0 0.0)
(setq PT1 (1.0 2.0 0.0))
Command:

When typing in an explicit point list, the (quote) function will tell AutoLISP not to evaluate the list.

Explanation: the (quote) function

A point list can be explicitly typed in using the (quote) function or its shortcut, a single quote in front of the list.

(quote ( list )) or ( list )

The (quote) function returns the list unevaluated. The (quote) function can be used with any AutoLISP expression, not just lists.

Example

Command: (setq PT1 (quote (1.0 2.0 0.0))) or (setq PT1 ‘(1.0 2.0 0.0))
(1.0 2.0 0.0)
Command:

PRACTICE

Establish three points, PT1, PT2 and PT3, whose coordinates are(0.0 0.0 0.0), (1.0 2.0 0.0), and (6.0 3.0 0.0) respectively. Estimated time for completion: 5 minutes.

See also  Loading an AutoLISP File
Back to top button