Fork me on GitHub
#emacs
<
2024-02-01
>
teodorlu11:02:37

Hi! In Clojure, I can (str something) to get a string of something. Is there a similar function in Emacs Lisp? I found specific “type to string” functions:

(number-to-string 42)
;; => "42"

(symbol-name 'org-mode)
;; => "org-mode"
I looked quickly at https://github.com/magnars/s.el too, but didn’t find a clojure.core/str replacement.

tomd12:02:39

You can use format to do most things, I think:

(format "%s" 42)
;; => "42"
Not sure if there is a more direct function I'm forgetting

👍 1
djm12:02:48

(number-to-string 42)

tomd12:02:01

Maybe reread the question

djm12:02:14

Oh, sorry!

🙂 1
tomd12:02:28

Having had a bit of a search, prin1-to-string looks like a good candidate, although it's not variadic

1
👍 1
teodorlu13:02:43

Awesome, prin1-to-string and format were just what I was looking for. Thank you! 💯

👍 1
teodorlu13:02:31

I was able to write a vararg version:

(defun teod/str (&rest args)
  (apply 'concat (mapcar 'prin1-to-string args)))

(teod/str 1 2 'org-mode)
;; => "12org-mode"
But I think I’ll probably just lean on the built-in functions instead. Thanks again!

🎉 1