[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: string to list



Excerpts from internet.listserv.info-mcl: 12-Feb-94 string to list by
Youngcook Jun@symcom.mat 
> Can anybody help me how to convert a string to a list?
> For example, how can I make "How are you?" in the form of (How are you?)
> and vise versa?

(coerce 'list "How are you?")

returns

(#\H #\o #\w #\space #\a #\r #\e #\space ...)

If you want to make each word a symbol, you should do something like this:

(let ((string "How are you?"))
  (do ((counter 0)
       (word (multiple-value-list (read-from-string string nil nil))
             (multiple-value-list (read-from-string (subseq string
counter) nil nil)))
       (words nil))
      ((not (first word))
       (reverse words))
    (incf counter (second word))
    (push (first word) words)))

This doesn't seem to elegant, tho. It returns:

(how are you?)

Robby