Split a character string based on change of character: Difference between revisions

m (→‎{{header|Fortran}}: Crossreference.)
Line 247:
 
=={{header|Common Lisp}}==
 
<lang lisp>(defun split (string)
(loop :for prev := nil :then c
:for c :across string
:do (format t "~:[~;, ~]~c" (and prev (char/= c prev)) c)))
 
(split "gHHH5YY++///\\")
</lang>
{{out}}
<pre>g, HHH, 5, YY, ++, ///, \</pre>
 
Doing more work that what's being ask, the following solution builds a list of strings then output it:
 
<lang lisp>(defun split (string)
(flet ((make-buffer ()
Anonymous user