1

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?

Drew
  • 77,472
  • 10
  • 114
  • 243

1 Answers1

2

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"
Muihlinn
  • 2,614
  • 1
  • 15
  • 22
wasamasa
  • 22,178
  • 1
  • 66
  • 99