Skip to content

Instantly share code, notes, and snippets.

@shirok
Last active November 11, 2017 08:58
Show Gist options
  • Save shirok/20c63902b195b0e03a55ecf066ca30bf to your computer and use it in GitHub Desktop.
Save shirok/20c63902b195b0e03a55ecf066ca30bf to your computer and use it in GitHub Desktop.
;; objsは文字列のリストに限らず任意のオブジェクトのリスト
(defun join (separator objs)
(format nil "~{~a~#,1^~a~}" (mapcan (lambda (s) (list s separator)) objs)))
;; separatorが固定なら多少わかりやすい。というかこのケースならformatを直接書くだろう。
(defun join-by-comma (objs)
(format nil "~{~a~^, ~}" objs))
#|
[6]> (join "-" '(tic tac toe))
"TIC-TAC-TOE"
[7]> (join-by-comma '(tic tac toe))
"TIC, TAC, TOE"
|#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment