2
votes

The following piece of code gives me the expected result:

(let ((name 'test)
      (args '("arg1" "arg2")))
     `(defun ,name ,@args))

;; (DEFUN TEST "arg1" "arg2")

Why if args is a list of symbols does a QUOTE appear?

(let ((name 'test)
      (args '('arg1 'arg2)))
     `(defun ,name ,@args))

;; (DEFUN TEST (QUOTE ARG1) 'ARG2)
1
('arg1 'arg2) isn't a list of symbols, it's a list of lists. The first list is (quote arg1) and the second is (quote arg2). - Joshua Taylor
I think the standard printer does newbies a big disservice by printing the data (quote x) as 'x. - Sylwester

1 Answers

8
votes

The reader expands 'symbol to (quote symbol). So in your case

'('arg1 'arg2)

is equivalent to

(quote ((quote arg1) (quote arg2)))

which evaluates to this list:

((quote arg1) (quote arg2))

Evaluating your form starting with the backquote results in splicing the list elements ((quote arg1) and (quote arg2)) at the same position in the resulting list (defun ...) as the strings before.

I don't know why your implementation prints the first spliced element expanded but not the second. However, as mentioned above, both forms are equivalent, when read.