@Anonymous wrote:
....Our function to convert our list would look like this :
(setq d (mapcar 'dtr c))
....
The function could also be written like this :
(setq d (mapcar (quote dtr) c))
.... quote command is used for list that should not be evaluated by list function.
But here I see :
(setq d (mapcar (quote dtr) c))
I don't understand why the quote function is used here.
....
I'm not quite sure, either, and it doesn't seem to be explained in Help anywhere that I can find, but I think, at least in part, it has to do with distinguishing a function name from the possibility of a variable that could have the same name. Without the ' before it, AutoLisp will try to evaluate the term as if it's a variable. For example, I have a (defun)'d command called ZL which Zooms to the drawing Limits, and which gets loaded in every drawing. If I use the (type) function to find out what ZL is:
Command: (type ZL)
nil
That's apparently the result of AutoLisp's thinking it's a variable that needs to be evaluated. But if I put the apostrophe before it, it tells AutoLisp not to evaluate it for content as a variable, in which case it can tell that it's a SYMbol:
Command: (type 'ZL)
SYM
If I set some value into ZL as a variable name:
Command: (setq ZL 23.45)
23.45
then when I ask what type it is without the apostrophe, it evaluates it as a variable, and knows what kind of content it holds:
Command: (type ZL)
REAL
But I don't fully understand some aspects of this whole subject, for example the difference between SYM and SUBR in what (type) returns, especially in relation to native AutoLisp function names, such as:
Command: (type car)
SUBR
It knows that one's not a variable name to be evaluated, even without the apostrophe, and it calls it something else if you include that:
Command: (type 'car)
SYM
I also don't understand the fact that it also "knows" [or "thinks"?] something that has not been defined is a SYMbol when I put an apostrophe before it:
Command: (type 'whatever)
SYM
which throws into question the return from (type 'ZL) earlier -- apparently it doesn't really know that ZL is a defined command, but at least it knows from the apostrophe that it's not to be evaluated like a variable.
I could study more about (quote), (type), symbols vs. variables vs. subroutines, and functions that use the difference -- (mapcar), (apply), etc. -- but I'm accustomed enough to the apostrophe prefix in those situations that I don't think much about it any more.
Another use of the apostrophe as a prefix is in working with System Variable names. Both the (getvar) and (setvar) can take a System Variable name in either of two forms: with double-quotes at both ends, or with an apostrophe only at the beginning [which is what I always use -- it's shorter!]. These are both valid and equivalent:
(setvar "osmode" 0)
or
(setvar 'osmode 0)
Help for (setvar) uses the former in its example, but Help for (getvar) uses the latter [even though it describes the argument as a string]. But I haven't seen any description of why either a STRing or a SYMbol can be used in these functions.
Kent Cooper, AIA