5

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)))

3 Answers 3

16

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).

Sign up to request clarification or add additional context in comments.

Comments

6

Build a list of the values:

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

Comments

3

try:

`(,str1 ,str2)

1 Comment

A bit complex -- a simeple (list str1 str2) would do as well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.