tags:

views:

279

answers:

3

I wrote the function

(defun test ()
  (let ((str1 "foo") (str2 "bar"))
    (loop for s in '(str1 str2) do (message s))))

but it does not work. The Elisp Backtrace message is:

Debugger entered--Lisp error: (wrong-type-argument stringp str1)

How can I make it work?

P.S.: the following modified version works perfectly, but I need the original version

(defun test1 ()
  (loop for s in '("asdf" "fdsa") do (message s)))
+1  A: 

try:

`(,str1 ,str2)
dsm
A bit complex -- a simeple (list str1 str2)would do as well
HD
+12  A: 

The quote operator (for which the apostrophe is syntactic sugar) means that its arguments are not evaluated, i.e. (quote (str1 str2)) returns a list of two symbols. Use list instead: (list str1 str2).

Svante
+4  A: 

Build a list of the values:

(defun test ()
  (let ((str1 "foo") (str2 "bar"))
    (loop for s in (list str1 str2) do (message s))))