Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!zaphod.mps.ohio-state.edu!wuarchive!udel!princeton!phoenix!eliot From: eliot@phoenix.Princeton.EDU (Eliot Handelman) Newsgroups: comp.lang.lisp Subject: Re: Building a string, char-by-char -- more details (HELP!) Message-ID: <2990@idunno.Princeton.EDU> Date: 2 Oct 90 03:51:29 GMT References: <51809@brunix.UUCP> Sender: news@idunno.Princeton.EDU Organization: Shitson University, New Crapsey Lines: 32 In article <51809@brunix.UUCP> dkb@cs.brown.edu (Dilip Barman) writes: ; ;How can I coerce the string into being a list component?? This has ;me stumped! Thanks in advance. If READ-FROM-STRING acted reasonably, you could use it like this: (defun string->list (string) (let ((words '()) (index 0)) (loop (multiple-value-bind (word next-index) (read-from-string string nil nil :start index) (setq index next-index) (if word (push word words) (return (nreverse words))))))) > (string->list "It was a dark and stormy night") (IT WAS A DARK AND STORMY NIGHT) Unfortunately, READ-FROM-STRING throws an error if it sees read-macros, like commas. The solution is to write your own version, which reads characters from a string (using SCHAR), preprocesses special characters (like comma), detects the end of the word, then hands the string and indicies to SUBSEQ, which operates on the string. Intern the result, push on a list, NREVERSE when done and voila! It really is a pain to to this in CL. It was so much easier in the old Franz Lisp, because strings and atoms were identical. --eliot