Last active
September 28, 2023 10:51
-
-
Save tompurl/5174818 to your computer and use it in GitHub Desktop.
Common Lisp function that converts a list into a string of concatenated characters.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun numlist-to-string (lst) | |
(when lst | |
(concatenate 'string | |
(write-to-string (car lst)) (numlist-to-string (cdr lst))))) | |
; Convert a list of numbers into a number | |
; (list 1 2 3 4) => 1234 | |
(parse-integer (numlist-to-string (list 1 2 3 4))) |
This should be the standard way:
(coerce some-list-of-chars 'string)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I know it's old, but I guess the "better" version would be:
This ensures that the function always returns the string (although sometimes it might be empty), and works for arbitrary things to concatenate them.
I guess it would also be faster, since there would be no recursion.