6

I have a list of characters (?h ?e ?l ?l ?o) and i want to convert it to string "hello". Currently i use this structure:

(concat (mapcar (lambda (ch) (char-to-string ch)) s))

Is there a more elegant and idiomatic way to convert list of chars to a string in Elisp?

Mirzhan Irkegulov
  • 17,660
  • 12
  • 105
  • 166

2 Answers2

10

Elisp's concat returns a string:

(concat '(?h ?e ?l ?l ?o))

(Found it out from coerce implementation in cl)

Anton Kovalenko
  • 20,999
  • 2
  • 37
  • 69
7

There's also (apply #'string LIST-OF-CHARS).

Stefan
  • 27,908
  • 4
  • 53
  • 82
  • On my version of emacs (version 24.4) this also works without `#` as `(apply 'string LIST-OF-CHARS)` – lauir Apr 19 '20 at 16:55