I'm struggling with applying a defined value and sending to a list. The list does not reflect my desired results. I've never been good with bound and local variables. Suggestions?
Undesired result =(("Val1" VALUE1) ("Val2" VALUE2))
Desired result =(("Val1" 10.22) ("Val2" 99.99))
The key is the use of the apostrophe/single-quote: this operator instructs the AutoLISP interpreter to interpret what follows as literal data, not requiring evaluation. Consequently, the symbols
value1 &
value2 are not evaluated to yield the values they hold, but rather remain as symbols. I delve into this in far more detail with several examples in my tutorial on
The Apostrophe and the Quote Function.
For your particular example, the solution would be to construct the list using the
list function, which evaluates its supplied arguments:
(defun uservalues
( / saved_values
) )
)
)
(uservalues)
)
Note that it may be better practice to supply the values as arguments to the
uservalues function, and then assign the variable
saved_values to the return of this function, as in your current code, the variables
value1 and
value2 are global. For example:
(defun uservalues
( v1 v2
) )
)
(defun c:TEST
( / value1 value2
) (setq saved_values
(uservalues value1 value2
)) )
This is obviously a very contrived example.