2

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
  • emacs.stackexchange.com/tags/elisp/info Commented Jan 17, 2021 at 0:49
  • 1
    Does this answer your question? How to evaluate the variables before adding them to a list? Commented Jan 17, 2021 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. Commented Jan 17, 2021 at 19:06

1 Answer 1

3

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