All pastes #930524 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-03-06 17:47 UTC
rendered paste body
(defun join-string2 (string-list &key (join-by " ") (convert-to-string nil))
  (declare (ignorable convert-to-string))
  (let ((length-1 (1- (length string-list))))
    (with-output-to-string (s)
      (if (= length-1 0)
          (princ (first string-list) s)
          (progn
            (dolist (word (subseq string-list 0 length-1))
              (princ word s) (princ join-by s))
            (princ (nth length-1 string-list) s)))
      s)))
    
CL-USER> (join-string2 (list "a") :join-by "_")
"a"
CL-USER> (join-string2 (list "a" "b" "c") :join-by "_")
"a_b_c"