AutoLISP Evaluates every Expression

The LISP part of AutoLISP stands for list processing, which describes what happens when you run a routine: AutoLISP processes lists or, as we say here, evaluates expressions. If you type in an AutoLISP expression at the Command line it will return the results of the processed list.

Command: (+ 18 6)
24  Expressionresults

  • Each AutoLISP expression is enclosed in parentheses.
  • Expressions are made up of a function followed by arguments. The function is analogous to the “verb” or action of the expression, while the arguments are like the “nouns” or things that are acted upon.

  • AutoLISP expressions are evaluated from left to right. Example: Basic Math Functions

Example: Basic Math Functions

  • An AutoLISP expression may have multiple arguments.

Command: (+ 3 8 16 12 2)
41

Command: (- 60 15 12)
33

  • An AutoLISP expression can contain other AutoLISP expressions. Such nested expressions are evaluated from the innermost parentheses outward.

Command: (+ 3 8 (* 2 3))
17

  • Spaces are used to separate the different parts of an AutoLISP expression. Either a single space or multiple spaces, including tabs and carriage returns (the <enter> key), may be used. Spacing makes the expression more readable.

Command: (+ 6 3)
9
Command: (+ 6
(_> 3)
9

Note that in the last example, since we did not close our initial parentheses before hitting the <enter> key, AutoCAD returned with a different prompt “(_>” telling us that our AutoLISP expression is not complete and requires one more closing parenthesis.

See also  Setting Up an AutoLISP Routine

PRACTICE

Try out the following basic calculations. Estimated time for completion: 5 minutes.

(+ 8 4)
(7 3)
(* 5 2)
(/ 10 5)

(+ 10 17 21)
(* 3 12 (17 5))
(+ 15 5 (* 6 4))
(/ (+ 6 3) (18 15))

Higher Math Functions

AutoLISP is a math wizard. It can handle not only basic math functions but also anything that a good scientific calculator can do.

Practice

Try out the following expressions. Estimated time for completion: 5 minutes.

(abs 3.0)
(abs -3.0)
(sqrt 9)
(sqrt 9.0)
(min -3 7 6.0 10 0)
(max -3 7 6.0 10 0)
(sin (/ PI 2))
(1+ 3) (1- 3)

Back to top button