From: Hrvoje Niksic
Subject: Parsing a simple string
Date: 
Message-ID: <kigwwrf8ssn.fsf@jagor.srce.hr>
I'm doing my first steps in CL programming, and have found an
obstacle.  I have a file of the following format:

string number
...

That is, each lines looks something like "foo 5" (the delimiter is one
SPC character).  I know how to read lines from the file using
`read-line', but I'd like to parse the string as to get the string
"foo" and number 5.  What's the best way to do it?  Any pointers?

Thanks.

-- 
Hrvoje Niksic <·······@srce.hr> | Student at FER Zagreb, Croatia
--------------------------------+--------------------------------
main(){printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-0x60);}

From: Erik Naggum
Subject: Re: Parsing a simple string
Date: 
Message-ID: <3067028325983943@naggum.no>
* Hrvoje Niksic
| I'm doing my first steps in CL programming, and have found an obstacle.
| I have a file of the following format:
| 
| string number
| ...
| 
| That is, each lines looks something like "foo 5" (the delimiter is one
| SPC character).  I know how to read lines from the file using
| `read-line', but I'd like to parse the string as to get the string "foo"
| and number 5.  What's the best way to do it?  Any pointers?

since the delimiter is a single space, let's exploit that.
(position #\Space <input-line>) yields its position.
(subseq <input-line> 0 <position>) yields the string.
(parse-integer <input-line> :start <position>) yields the number.

#\Erik
-- 
how to beat Microsoft, death, and poverty: in July 1994, there were more
references to my name (3039) in gopherspace than to Microsoft (2557), death
(2530), and poverty (2410).  (http://veronica.sonoma.edu:8001/top1000.html)
From: Marco Antoniotti
Subject: Re: Parsing a simple string
Date: 
Message-ID: <s08zpwa4ec1.fsf@crawdad.ICSI.Berkeley.EDU>
Erik Naggum <····@naggum.no> writes:

> 
> * Hrvoje Niksic
> | I'm doing my first steps in CL programming, and have found an obstacle.
> | I have a file of the following format:
> | 
> | string number
> | ...
> | 
> | That is, each lines looks something like "foo 5" (the delimiter is one
> | SPC character).  I know how to read lines from the file using
> | `read-line', but I'd like to parse the string as to get the string "foo"
> | and number 5.  What's the best way to do it?  Any pointers?
> 
> since the delimiter is a single space, let's exploit that.
> (position #\Space <input-line>) yields its position.
> (subseq <input-line> 0 <position>) yields the string.
> (parse-integer <input-line> :start <position>) yields the number.
> 

That is to say....

	(let* ((line (read-line open-file-stream))
	       (space-pos (position #\Space line))
	       (s (subseq line 0 space-pos))
               (n (parse-integer line :start space-pos))
              )
           ;; do stuff
         )

How to open the file and test for eof is your homework :)

-- 
Marco Antoniotti - Resistente Umano
From: Zlatko Calusic
Subject: Re: Parsing a simple string
Date: 
Message-ID: <87ybbujrtg.fsf@pc-zcalusic.srce.hr>
Marco Antoniotti <·······@crawdad.icsi.berkeley.edu> writes:

> How to open the file and test for eof is your homework :)

Beep error. This is not homework.

We're trying to learn Common Lisp, and think that a few clever
questions posted to this group could improve our knowledge a lot (with
help from the good people, just like you).

Hrvoje programmed in Emacs Lisp for some time now, and I started to
learn Lisp just about a month ago.

I installed GCL, CMU CL, and Allegro CL (thanks to some very good
people at Franz Inc.) on my Linux machine, and then we spent a few
sleepless nights diving into world of Lisp.

BTW, after having solved the string splitting problem, we were able to
write three different algorithms to solve our first problem.

3 algorithms x 3 compilers = good start in exploring CL. :)

Thanks for your help, and also thanks to Erik Naggum who responded
first with great solution (which we used immediately in our program).

BTW, problem arose when we wanted to use something like 'substring' in
Emacs Lisp, and started searching for it with (apropos 'string) :)
After some time, we surrendered (we saw few screens full of functions,
and subseq wasn't there :)

Regards,
-- 
Posted by Zlatko Calusic                     E-mail: <········@srce.hr>
-----------------------------------------------------------------------
Faculty of Electrical Engineering and Computer Science, Zagreb, Croatia

		  I cna ytpe 300 wrods pre mniuet!!!