> 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.
> 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'.
> 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 :-)
* Ed Symanzik <z...@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:
* Ed Symanzik <z...@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:
* Ed Symanzik <z...@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.
> (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 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.
> 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).
Ed Symanzik <z...@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 <b...@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