From the Autocad command line
(emphasis added):
Command: (defun local-test ( / va vb)
(_> (setq va "A")
(_> (setq vb "B")
(_> (princ (strcat "\nThe value of va is " va))
(_> (princ (strcat "\nThe value of vb is " vb))
(_> (princ)
(_> )
LOCAL-TEST
Command: (setq va "Z" vb "X")
"X"
Command: !va
"Z"
Command: !vb
"X"
Command: (local-test)
The value of va is A
The value of vb is B
Command: !va
"Z"
Command: !vb
"X"
When you make a variable local, you make it local to
the function that you used it in.
The variables
va and
vb are
global variables that you set at the command line using
(setq va "Z" vb "X")
When you run the function (local-test) you set variables
va and
vb,
local to the function, to
A and
B respectively. As local variables, they are 'emptied' when the function ends. But the variables that you set
globally at the command line
retained their value.
Doing this
(defun local-test ( / )
(setq va "A")
(setq vb "B")
(princ (strcat "\nThe value of va is " va))
(princ (strcat "\nThe value of vb is " vb))
(princ)
)
would change the value of our
global variables because they are not local to this function (
notice that they are no longer following our slash). So when you test the variable values at the command line after running
this function, you'll get a different result.
Command: !va
"A"
Command: !vb
"B"