From: Cad Bilbao
Subject: Reading a list
Date: 
Message-ID: <604dab8.0111051045.375b18d8@posting.google.com>
Hi!

I'm trying to read a list by using LISP. My list is a file that
resembles this:

----------//-------
1,John,Engineer
2,Peter,Director
3,Caroll,Engineer
...
-------------//-----

I read on the Internet that this kind of file is called a "comma
separated list". Could anybody help me to read these files?

I was searching the web, but I did not find any tip...

Thank you very much

From: Marco Antoniotti
Subject: Re: Reading a list
Date: 
Message-ID: <y6c668p6n70.fsf@octagon.mrl.nyu.edu>
···@bilbao.com (Cad Bilbao) writes:

> Hi!
> 
> I'm trying to read a list by using LISP. My list is a file that
> resembles this:
> 
> ----------//-------
> 1,John,Engineer
> 2,Peter,Director
> 3,Caroll,Engineer
> ...
> -------------//-----
> 
> I read on the Internet that this kind of file is called a "comma
> separated list". Could anybody help me to read these files?

(defun almost-doing-your-homework (the-file)
   (with-open-file (f the-file :direction :input)
      (loop for line = (read-line f nil nil)
            while line
	        do (print line))))

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: Janis Dzerins
Subject: Re: Reading a list
Date: 
Message-ID: <87itcphwd8.fsf@asaka.latnet.lv>
···@bilbao.com (Cad Bilbao) writes:

> Hi!
> 
> I'm trying to read a list by using LISP.

How nice that you're trying. Could you also please tell us *how* are
you doing this?

>  My list is a file that resembles this:
> 
> ----------//-------
> 1,John,Engineer
> 2,Peter,Director
> 3,Caroll,Engineer
> ...
> -------------//-----
> 
> I read on the Internet that this kind of file is called a "comma
> separated list". Could anybody help me to read these files?

Well -- do *you* really need help in reading the file?

> I was searching the web, but I did not find any tip...

Oh how nice you told about what else you're doing.

> Thank you very much

Thank you for telling us about your deeds. And you know what -- you
are not alone! You are already a third person to ask this kind of
question recently. Try searching the web more carefully. I suggest
starting at http://groups.google.com.

-- 
Janis Dzerins

  Eat shit -- billions of flies can't be wrong.
From: Erik Haugan
Subject: Re: Reading a list
Date: 
Message-ID: <87n1202q7a.fsf@kometknut.neitileu.no>
* ···@bilbao.com (Cad Bilbao)
> I'm trying to read a list by using LISP. My list is a file that
> resembles this:
> 
> ----------//-------
> 1,John,Engineer
> 2,Peter,Director
> 3,Caroll,Engineer
> ...
> -------------//-----
> 
> I read on the Internet that this kind of file is called a "comma
> separated list". Could anybody help me to read these files?

Shure.  Here's how:

1 learn some Lisp (start at www.lisp.org)
2 try to solve the problem yourself
3 if you still need help, post a message in this forum stating:
3.1 that you need help with your homework
3.2 the exact wording of the assignment
3.3 what you have tried so far
3.4 that you really like what you have learned about Lisp so far (for extra
    goodwill :-)

Good luck.

Erik
From: Ed Symanzik
Subject: Re: Reading a list
Date: 
Message-ID: <3BEAFC72.BD2B081C@msu.edu>
I've been trying a similar thing to read /etc/passwd.

  (setq passwd-readtable (copy-readtable))
  (set-syntax-from-char #\: #\space passwd-readtable))
  (loop for char in 
     '(#\tab #\space #\" #\# #\' #\( #\) #\, #\; #\\ #\` #\|) do
     (set-syntax-from-char char #\A passwd-readtable))

  (setq orig-readtable (copy-readtable *readtable*))
  (copy-readtable passwd-readtable *readtable*)

  (setq in (open "/etc/passwd" :direction :input))


However, this is bad as the readtable applies to current
code.

Is there a way to apply a different readtable to a stream?

Or, as is likely the case, am I out in the weeds?
From: Vebjorn Ljosa
Subject: Re: Reading a list
Date: 
Message-ID: <cy3r8r8r0n5.fsf@ljosa.com>
* Ed Symanzik <···@msu.edu>
| I've been trying a similar thing to read /etc/passwd.
| 
|   (setq passwd-readtable (copy-readtable))
|   (set-syntax-from-char #\: #\space passwd-readtable))
|   (loop for char in 
|      '(#\tab #\space #\" #\# #\' #\( #\) #\, #\; #\\ #\` #\|) do
|      (set-syntax-from-char char #\A passwd-readtable))
| 
|   (setq orig-readtable (copy-readtable *readtable*))
|   (copy-readtable passwd-readtable *readtable*)
| 
|   (setq in (open "/etc/passwd" :direction :input))
| 
| 
| However, this is bad as the readtable applies to current
| code.
| 
| Is there a way to apply a different readtable to a stream?

You need to make sure that only stuff from the password file is being
read with *readtable* is bound to your customized readtable.  This
works:

(defvar *passwd-readtable* (copy-readtable))

(set-syntax-from-char #\: #\space *passwd-readtable*)

(loop 
    for char in 
      '(#\tab #\space #\" #\# #\' #\( #\) #\, #\; #\\ #\` #\|) 
    do
      (set-syntax-from-char char #\A *passwd-readtable*))

(setq in (let ((*readtable* *passwd-readtable*)
	       (stream (open "/etc/passwd" :direction :input)))
	   (read stream)))
=> root

-- 
Vebjorn Ljosa
From: Vebjorn Ljosa
Subject: Re: Reading a list
Date: 
Message-ID: <cy3r8r8o6z3.fsf@ljosa.com>
* Ed Symanzik <···@msu.edu>
| I've been trying a similar thing to read /etc/passwd.
| 
|   (setq passwd-readtable (copy-readtable))
|   (set-syntax-from-char #\: #\space passwd-readtable))
|   (loop for char in 
|      '(#\tab #\space #\" #\# #\' #\( #\) #\, #\; #\\ #\` #\|) do
|      (set-syntax-from-char char #\A passwd-readtable))
| 
|   (setq orig-readtable (copy-readtable *readtable*))
|   (copy-readtable passwd-readtable *readtable*)
| 
|   (setq in (open "/etc/passwd" :direction :input))
| 
| 
| However, this is bad as the readtable applies to current
| code.
| 
| Is there a way to apply a different readtable to a stream?

You need to make sure that only stuff from the password file is being
read with *readtable* bound to your customized readtable.  This works:

(defvar *passwd-readtable* (copy-readtable))

(set-syntax-from-char #\: #\space *passwd-readtable*)

(loop 
    for char in 
      '(#\tab #\space #\" #\# #\' #\( #\) #\, #\; #\\ #\` #\|) 
    do
      (set-syntax-from-char char #\A *passwd-readtable*))

(setq in (let ((*readtable* *passwd-readtable*)
	       (stream (open "/etc/passwd" :direction :input)))
	   (read stream)))
=> root

-- 
Vebjorn Ljosa
From: Erik Naggum
Subject: Re: Reading a list
Date: 
Message-ID: <3214292868309227@naggum.net>
* Ed Symanzik <···@msu.edu>
| Is there a way to apply a different readtable to a stream?

  Have you tried a binding *readtable* across the relevant operations?

///
-- 
  Norway is now run by a priest from the fundamentalist Christian People's
  Party, the fifth largest party representing one eighth of the electorate.
-- 
  Carrying a Swiss Army pocket knife in Oslo, Norway, is a criminal offense.
From: Ed Symanzik
Subject: Re: Reading a list
Date: 
Message-ID: <3BF18039.1C2AD1AE@msu.edu>
Ed Symanzik wrote:
> 
> I've been trying a similar thing to read /etc/passwd.
> 
>   (setq passwd-readtable (copy-readtable))
>   (set-syntax-from-char #\: #\space passwd-readtable))
>   (loop for char in
>      '(#\tab #\space #\" #\# #\' #\( #\) #\, #\; #\\ #\` #\|) do
>      (set-syntax-from-char char #\A passwd-readtable))
> 
>   (setq orig-readtable (copy-readtable *readtable*))
>   (copy-readtable passwd-readtable *readtable*)
> 
>   (setq in (open "/etc/passwd" :direction :input))


Thanks for everyone's responses.  I was thinking it would
be a handy thing to let Lisp reader handle the parsing,
specially for comma separated values with optional
quotes.  This was working quite nicely until I realised
that strings are read as symbols and uppercased.  Not
good for usernames and pathnames.  Back to writing my
own parser.

Thanks again.
From: Martti Halminen
Subject: Re: Reading a list
Date: 
Message-ID: <3BF1A6A2.F92745D9@kolumbus.fi>
Ed Symanzik wrote:
>
> Thanks for everyone's responses.  I was thinking it would
> be a handy thing to let Lisp reader handle the parsing,
> specially for comma separated values with optional
> quotes.  This was working quite nicely until I realised
> that strings are read as symbols and uppercased.  Not
> good for usernames and pathnames.  Back to writing my
> own parser.

Did you read Hyperspec section 23.1.2 ?

www.xanalys.com/software_tools/reference/HyperSpec/Body/sec_23-1-2-1.html

--
From: Ed Symanzik
Subject: Re: Reading a list
Date: 
Message-ID: <3BF26F43.BF630480@msu.edu>
Martti Halminen wrote:

> Did you read Hyperspec section 23.1.2 ?
> 
> www.xanalys.com/software_tools/reference/HyperSpec/Body/sec_23-1-2-1.html

Thanks.  I missed that.

Now, what happens if changes their gecos to something like
(+ 2 3) ?  Lisp will be fine with that as a symbol name, right?

What about a gecos of *readtable* ?  Will that get me in trouble?

Is there anything that makes this a poor method of parsing files?
Technically?  Style?
From: Brian P Templeton
Subject: Re: Reading a list
Date: 
Message-ID: <87herjdg5j.fsf@tunes.org>
Ed Symanzik <···@msu.edu> writes:

> Now, what happens if changes their gecos to something like
> (+ 2 3) ?  Lisp will be fine with that as a symbol name, right?
> 
Yes.

-- 
BPT <···@tunes.org>	    		/"\ ASCII Ribbon Campaign
backronym for Linux:			\ / No HTML or RTF in mail
	Linux Is Not Unix			 X  No MS-Word in mail
Meme plague ;)   --------->		/ \ Respect Open Standards
From: Tim Bradshaw
Subject: Re: Reading a list
Date: 
Message-ID: <fbc0f5d1.0111140845.3512bca1@posting.google.com>
> This was working quite nicely until I realised
> that strings are read as symbols and uppercased.  Not
> good for usernames and pathnames.  Back to writing my
> own parser.

Look at READTABLE-CASE. (but if you're reading passwd files you
probably want your own reader anyway).

--tim