From: Kid Icarus
Subject: I'd like some help with a project I'm doing.
Date: 
Message-ID: <14e0a059.0111200628.6becd2f9@posting.google.com>
I'm a student and need help! Urgently!

We were given a project (a case-based classifier, if you're
interested) and part of the project was to read in a data file and
parse it.

The data file is of the form:
3,88,58,11,54,24.8,0.267,22,0
6,92,92,0,0,19.9,0.188,28,0
1,103,80,11,82,19.4,0.491,22,0
1,101,50,15,36,24.2,0.526,26,0
........

and I need to get into the form:
((3 88 58 11 54 24.8 0.267 22 0)
 (6 92 92 0 0 19.9 0.188 28 0)
 (1 103 80 11 82 19.4 0.491 22 0)
 (1 101 50 15 36 24.2 0.526 26 0)
........)

I have no trouble reading the file and selecting whatever line I want,
I just can't parse it into the form (x x x x x x x x x x). I tried
using:

(read-from-string "1,93,70,31,0,30.4,0.315,23,0")

but that just returns 1. If anyone has any ideas, could they e-mail me
(if possible).
Thanks!

From: Vebjorn Ljosa
Subject: Re: I'd like some help with a project I'm doing.
Date: 
Message-ID: <cy3k7wlpehg.fsf@ljosa.com>
* ···············@hotmail.com (Kid Icarus)
| (read-from-string "1,93,70,31,0,30.4,0.315,23,0")
| 
| but that just returns 1. If anyone has any ideas, could they e-mail me
| (if possible).

READ-FROM-STRING returns a secondary value, which is the index of the
first character in the string that was _not_ read.

You can use the keyword argument :START to tell READ-FROM-STRING not
to read from the beginning of the string, but from somewhere within.

That should give you some ideas about how to proceed.

-- 
Vebjorn Ljosa
From: Marco Antoniotti
Subject: Re: I'd like some help with a project I'm doing.
Date: 
Message-ID: <y6cr8qt5qur.fsf@octagon.mrl.nyu.edu>
···············@hotmail.com (Kid Icarus) writes:

> I'm a student and need help! Urgently!
> 
> We were given a project (a case-based classifier, if you're
> interested) and part of the project was to read in a data file and
> parse it.
> 
> The data file is of the form:
> 3,88,58,11,54,24.8,0.267,22,0
> 6,92,92,0,0,19.9,0.188,28,0
> 1,103,80,11,82,19.4,0.491,22,0
> 1,101,50,15,36,24.2,0.526,26,0
> ........
> 
> and I need to get into the form:
> ((3 88 58 11 54 24.8 0.267 22 0)
>  (6 92 92 0 0 19.9 0.188 28 0)
>  (1 103 80 11 82 19.4 0.491 22 0)
>  (1 101 50 15 36 24.2 0.526 26 0)
> ........)
> 
> I have no trouble reading the file and selecting whatever line I want,
> I just can't parse it into the form (x x x x x x x x x x). I tried
> using:
> 
> (read-from-string "1,93,70,31,0,30.4,0.315,23,0")
> 

You need a "parser" for the string.

1 - split the string at the commas

	(split-sequence "1,93,70,31,0,30.4,0.315,23,0" :separator #\,)

    this will yield the list of strings

	("1" "93" "70" "31" "0" "30.4" "0.315" "23" "0")

    let's call it 'result'.

2 - transform it into a list of numbers

	(mapcar #'read-from-string result)

    this yields

	(1 93 70 31 0 30.4 0.315 23 0)

    you are almost done.

Of course you need SPILT-SEQUENCE.  You can find it in many places
like the CLOCC and ccLan.

Cheers

-- 
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group        tel. +1 - 212 - 998 3488
719 Broadway 12th Floor                 fax  +1 - 212 - 995 4122
New York, NY 10003, USA                 http://bioinformatics.cat.nyu.edu
                    "Hello New York! We'll do what we can!"
                           Bill Murray in `Ghostbusters'.
From: Christopher Stacy
Subject: Re: I'd like some help with a project I'm doing.
Date: 
Message-ID: <ug079ebbf.fsf@spacy.Boston.MA.US>
>>>>> On 20 Nov 2001 06:28:25 -0800, Kid Icarus ("Kid") writes:
 Kid> (read-from-string "1,93,70,31,0,30.4,0.315,23,0")
 Kid> but that just returns 1. If anyone has any ideas, could they
 Kid> e-mail me (if possible).

READ-FROM-STRING takes START and END keyword arguments.
You might prefer to use the function PARSE-INTEGER, though.
You should also read about the function POSITION.
From: Christian Nyb�
Subject: Re: I'd like some help with a project I'm doing.
Date: 
Message-ID: <87oflxwizd.fsf@nybo.no>
···············@hotmail.com (Kid Icarus) writes:

> (read-from-string "1,93,70,31,0,30.4,0.315,23,0")
> 
> but that just returns 1. 

Not true.  It returns 1 (the element read) _and_ the position at which
read-from-string stopped reading.  See
http://www.xanalys.com/software_tools/reference/HyperSpec/Body/fun_read-from-string.html

Perhaps you could use this second return value for something useful?
You can get to it by using multiple-value-bind, like this:

cl-user(230): (multiple-value-bind (element position) 
		  (read-from-string "1138,93,70,31,0,30.4,0.315,23,0")
		(format nil "Element: ~A~%Position: ~A~%" element position))
"Element: 1138
Position: 4
"
-- 
chr
From: Kid Icarus
Subject: Re: I'd like some help with a project I'm doing.
Date: 
Message-ID: <14e0a059.0111220230.30aadf87@posting.google.com>
> I have no trouble reading the file and selecting whatever line I want,
> I just can't parse it into the form (x x x x x x x x x x). I tried
> using:
> 
> (read-from-string "1,93,70,31,0,30.4,0.315,23,0")
> 
> but that just returns 1. If anyone has any ideas, could they e-mail me
> (if possible).
> Thanks!

Thanks to all who replied - managed to get this from somewhere. Does
_exactly_ what I needed.

(defun parser (string &optional (delimiter #\,))
   (read-from-string 
       (concatenate 'string "(" (substitute #\space delimiter string)
")")))
From: Christophe Rhodes
Subject: Re: I'd like some help with a project I'm doing.
Date: 
Message-ID: <sqy9kzyrty.fsf@cam.ac.uk>
···············@hotmail.com (Kid Icarus) writes:

> > I have no trouble reading the file and selecting whatever line I want,
> > I just can't parse it into the form (x x x x x x x x x x). I tried
> > using:
> Thanks to all who replied - managed to get this from somewhere. Does
> _exactly_ what I needed.
> 
> (defun parser (string &optional (delimiter #\,))
>    (read-from-string 
>        (concatenate 'string "(" (substitute #\space delimiter string)
> ")")))

You are aware of the security implications of doing this on untrusted
data, yes?

Christophe
-- 
Jesus College, Cambridge, CB5 8BL                           +44 1223 510 299
http://www-jcsu.jesus.cam.ac.uk/~csr21/                  (defun pling-dollar 
(str schar arg) (first (last +))) (make-dispatch-macro-character #\! t)
(set-dispatch-macro-character #\! #\$ #'pling-dollar)