0

I want to string-join a list of strings, one of which is returned by a function call.

Like this:

(defun foobar () "foobar")
(string-join '("foo" (foobar) "bar") "|")

That results in Wrong type argument: characterp, foobar and not in "foo|foobar|bar" as expected.

What's the elegant way to do that?

3
  • 1
    Does this answer your question? How to evaluate the variables before adding them to a list? – Drew Jan 17 at 19:04
  • There are multiple questions that deal with the same thing: quoting some sexp and expecting some part of the quoted sexp to be evaluate. It would be great if Someone (TM) created a general Q & A for that, as a Community question. Many, many questions like this one have been closed as dups of the one I cited, but that Q is not stated in as general a way as it could be. – Drew Jan 17 at 19:06
1

A quoted list doesn't evaluate its args, so it consists of a string, a list containing a symbol and another string. You can selectively evaluate it using backquote and unquote:

`("foo" ,(foobar) "bar") ;=> ("foo" "foobar" "bar")
(string-join `("foo" ,(foobar) "bar") "|") ;=> "foo|foobar|bar"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.