Created
August 8, 2020 12:45
-
-
Save abishek/07c3cdcf6e13635bc6204c47ab07a3bb to your computer and use it in GitHub Desktop.
A simple defun to split a space separated string into individual word strings. "one two three" into ("one" "two" "three") so to say.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun split-sentence-to-words (sentence) | |
(let ((word '())) | |
(loop for ch across sentence | |
if (member ch '(#\space #\tab #\,)) | |
collect (coerce (reverse word) 'string) into words and do (setf word '()) | |
else | |
do (push ch word) | |
finally (return (append words (coerce (reverse word) 'string)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@RainerJoswig on twitter helped me out: https://twitter.com/rainerjoswig/status/1292183185867120641?s=21
Here is my fixed version taking inspiration from his sample.
Yes, I could copy the aux and the flet. But these are things I am not super familiar with. So I'll stick to what I know until I grow up some more. But the real trick I needed was where the
append
is used.