Assigning Values to Symbols with Autolisp

One of the most powerful features of AutoLISP is the ability to store a variable and then use it again later. In AutoLISP, these variables are called symbols, and they may be assigned a value using the (setq) function.

Explanation: the (setq) function

(setq symbol expression)

  • The (setq) function must have two arguments, the symbol name and an expression assigned to the symbol name.

Command: (setq A 12.0)

  • A single (setq) command can set any number of variables.

(setq symbol1 expression1
symbol2 expression2
symbol3 expression3
);end setq

  • A symbol evaluates to its value. You can see the current value of a symbol at any time by typing an exclamation point (!) prior to the symbol name.

Command: (setq B “This is text”)
“This is text”

Command: !B
“This is text”

  • If no value has been assigned to a symbol, then its value is nil.Command: !C
    nil
  • If several values have been assigned to a symbol, AutoLISP remembers only the last one assigned.

PRACTICE

Try the following exercises using the (setq) function. Estimated time for completion: 5 minutes.

(setq A 5)
(setq B A)
(setq C (* A B))
(setq D (+ (* A B) C))
!A
!B
!C
!D
(setq D (+ D 15))
!D

See also  Using the Visual LISP Console Window
Back to top button