Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!cme!cam!ARTEMIS From: miller@cam.nist.gov (Bruce R. Miller) Newsgroups: comp.lang.lisp Subject: Re: Building a string, char-by-char -- more details (HELP!) Message-ID: <2863814023@ARTEMIS.cam.nist.gov> Date: 1 Oct 90 23:53:43 GMT References: <51809@brunix.UUCP> Sender: news@cam.nist.gov Followup-To: comp.lang.lisp Organization: NIST - Center for Computing and Applied Mathematics Lines: 40 In article <51809@brunix.UUCP>, Dilip Barman writes: > What I'm trying to do seems fraught with problems and I thought I'd > ask my question again with more details. Thanks to those who suggested > fill-pointers and treating a string as an array of characters, but I > am still having problems. What I want to be able to do is parse sentences > from an input file, delimited by periods. Other than periods, only a-z, A-Z, > slash (/), and dash (-) are considered non-white space. Words are delimited > by white space. What I want to create is not a string but a list component > (I discovered setting *print-escape* to nil to disable double quotes and > this should help). So, in reading > "This is sentence 1. > This is * sentence2." > I am trying to create: > > ( (THIS IS SENTENCE (NUMBER 1)) > (THIS IS SENTENCE2) > ) > > How can I coerce the string into being a list component?? This has > me stumped! Thanks in advance. Why, CONS it onto something, of course! In lisp ANYTHING can be a `list component' (cons "FOO" NIL) -> ("FOO") (cons 1 (cons "FOO" NIL)) -> (1 "FOO") etc. So, read characters and put them into a string, using the functions mentioned, stop when you get to anything you consider a delimiter, cons that onto a result and keep going till you get a period, then return the reverse of the result. This gives ("THIS" "IS" "SENTENCE2") And your homework will be done in no time. If you really want symbols instead of strings, use INTERN. And dont bother with *print-escape*; that only affects how things print, not how they are read. bruce