Skip to content

Instantly share code, notes, and snippets.

@tluyben
Last active July 27, 2023 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tluyben/ce5a0d9b949ab0dbbd47fb2743f0c24c to your computer and use it in GitHub Desktop.
Save tluyben/ce5a0d9b949ab0dbbd47fb2743f0c24c to your computer and use it in GitHub Desktop.
unicode handling, basic string to list
(defun string-to-list (string)
(mapcar #'princ-to-string (coerce string 'list)))
;; (string-to-list "123πŸš˜πŸšƒπŸš…456")
;; > ("1" "2" "3" "🚘" "πŸšƒ" "πŸš…" "4" "5" "6")
;; and
(defun list-to-string (list)
(let ((result ""))
(loop for x in list
do (setq result (concatenate 'string result x)))
result))
;; CL-USER> (list-to-string (string-to-list "123πŸš˜πŸšƒπŸš…456"))
;; "123πŸš˜πŸšƒπŸš…456"
;; nicer;
(defun concat (x y)
(concatenate 'string x y))
(defun list-to-string2 (list)
(reduce #'concat list))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment