From: Mike Dunn
Subject: Splitting strings
Date: 
Message-ID: <3508777F.D057472B@mindlink.bc.ca>
I'm a student with a minor problem and I'm looking for help.
(I'm *not* some kid whose trying to get out of homework).

I'm doing a project (robot simulation) in Allegro CL where I need to
split '(rotate-10,9) into '(rotate -10 9).  In other words, I'm trying
to split one object into two using markers in the object name.

I'm exploring converting the object into string, then iteratively
checking each letter to see if it is a place to be split.  The problem
is what to do once I've found it.  I can't seem to find an insert
charactor function (I'd insert a space, then convert it back to an
object).  Right now I'm think about creating a new string as I read
through the old string, then saving it and starting another new string
when I find a marker for a new word, but it seems there must be an
easier way.

FYI, the information is BASIC code read out of a text file using "read",
which converts the next section of text into an object, stopping at
whitespace.  An alternate solution would be to get read to stop at other
things (a -, number, or a comma), but I'm not sure how to do this
either.

Any help you can give me would be appreciated.
From: Rob Warnock
Subject: Re: Splitting strings
Date: 
Message-ID: <6eaa3s$2b9ui@fido.asd.sgi.com>
Mike Dunn  <·········@mindlink.bc.ca> wrote:
+---------------
| FYI, the information is BASIC code read out of a text file using "read",
| which converts the next section of text into an object, stopping at
| whitespace.  An alternate solution would be to get read to stop at other
| things (a -, number, or a comma), but I'm not sure how to do this either.
+---------------

I'd suggest reading the original BASIC file as "lines" (strings) and
doing the first-pass lexical parsing yourself (yes, with an ad-hoc lexer),
then perhaps calling "read-from-string" to intern the Lisp data once
you've found the lexical boundaries of the tokens. IMHO, it's a lot
easier than trying to second-guess Lisp's "read" (and it's also easier
to handle the inevitable error cases)...

That's what I did when writing an assembler in Scheme [don't ask], and
the lexer wasn't very big, just a few dozen lines of code.


-Rob

-----
Rob Warnock, 7L-551		····@sgi.com   http://reality.sgi.com/rpw3/
Silicon Graphics, Inc.		Phone: 650-933-1673 [New area code!]
2011 N. Shoreline Blvd.		FAX: 650-933-4392
Mountain View, CA  94043	PP-ASEL-IA