I'm trying to join a list of strings using mapconcat, but can't figure out how to include a variable as one of the list elements. Here's what I'm going for:
(mapconcat #'identity '("" "path" "to" "someplace") "/")
=> "/path/to/someplace"
But when I try to include a variable:
(let ((path "someplace"))
  (mapconcat #'identity '("" "path" "to" path) "/"))
=> Wrong type argument: sequencep, path
This doesn't work either:
(let ((path "someplace"))
  (mapconcat #'(lambda (x) (format "%s" x)) '("" "path" "to" path) "/"))
=> "/path/to/path"
Can anyone point out what I'm missing here?
You're quoting the list with ', which means that any symbols are included as symbols in the list, instead of being dereferenced as variables.
You can either use the list function:
(list "" "path" "to" path)
or use a backquote and a comma, to force evaluation of one of the list elements:
`("" "path" "to" ,path)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With