Skip to content

Instantly share code, notes, and snippets.

@jfacoustic
Created September 4, 2020 17:20
Show Gist options
  • Save jfacoustic/72ca11400fb108225393ec4a23a79109 to your computer and use it in GitHub Desktop.
Save jfacoustic/72ca11400fb108225393ec4a23a79109 to your computer and use it in GitHub Desktop.
Splits string by delimiter; default delimiter is \#space. (split-string "1 2 3 4") evaluates to ("1" "2" "3" "4").
(defun split-string (str &key (delimiter #\space))
(defun split-string-rec (str str-list delimiter-pos)
(if delimiter-pos
(let ((current (subseq str 0 delimiter-pos))
(remaining (subseq str (+ delimiter-pos 1) (length str))))
(split-string-rec remaining
(push current str-list)
(position delimiter remaining)))
(reverse (push str str-list))))
(split-string-rec str nil (position delimiter str)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment