I am trying to parse a comma separated string with Common lisp with the function below. For (separate-on-comma "a,b,c") I would expect the output ("a" "b" "c") but instead I get ("c" "c" "c").
What do I miss here?
(defun separate-on-comma (line)
(loop
with fields = ()
with field = (make-array 0 :element-type 'character :adjustable t :fill-pointer 0)
for x across line
when (char= x #\,)
do (push field fields)
and do (setf (fill-pointer field) 0)
else
do (vector-push-extend x field)
finally
(push field fields)
(return fields)))
Thanks.
split-sequencelibrary. Alternative implementation: usepositionandsubseqin a loop.(progn (ql:quickload "cl-ppcre") (cl-ppcre:split "," "a,b,c")) >("a" "b" "c")Now you can even use regexps for splitting a string.