SKILL: Difference Between List and Quote?
I’m puzzled: I thought
'(the single quote operator) were equivalent, but they produce different results in the following examples:
a=1 b=2 c=list(a b)
|- (1 2)
a=1 b=2 c='(a b)
|- (a b)
Can you tell me the difference between these expressions?
From: Damien Diederen <email@example.com>
Date: Wed, 23 Jan 2013 09:58:47 +0100
Yes. Example 1 is easy; focusing on the right side of the assignment,
is a normal function call. Each argument is to be evaluated, and the results—the contents of the
b variables—applied to the
list function, which builds a fresh list of its arguments. The result is thus:
Example 2 is a bit more complicated to understand. The first thing to remember is that:
is just a syntax shortcut for:
This is very important, because
quote is not a normal function. It is a special operator which admits a single argument, and returns it unevaluated. In this case, the single argument to quote is:
which, by the rules of the SKILL/SKILL++ program text parser (the reader), is a list of two symbols,
b. The result is thus simply:
Note that that list is built once, by the reader, and never touched again. Every evaluation of
quote will return that same list object. This is very different from e.g.:
which, while it produces a similar-looking result, allocates a fresh list on each call; that difference is crucial if the list if to be modified afterwards!
Hope this helps,