From: Michael Weber on 8 Sep 2009 18:09 On Sep 8, 11:28 pm, Francogrex <fra...(a)grex.org> wrote: > [BTW, I like also very much Michael Weber's tokenize he posted above > I'm using it now.] > Can I have this dos to unix conversion already set into sbcl so i > don't have to convert manually every file before reading it in? Do you actually need this with TOKENIZE, given that #\Return is part of :whitespace t?
From: Francogrex on 8 Sep 2009 18:31 On Sep 9, 12:09 am, Michael Weber <mw+goo...(a)foldr.org> wrote: > On Sep 8, 11:28 pm, Francogrex <fra...(a)grex.org> wrote: > > > [BTW, I like also very much Michael Weber's tokenize he posted above > > I'm using it now.] > > Can I have this dos to unix conversion already set into sbcl so i > > don't have to convert manually every file before reading it in? > > Do you actually need this with TOKENIZE, given that #\Return is part > of :whitespace t? TOKENIZE works well in sbcl (and ecl) directly in windows/dos files: I don't need to convert them to unix files first. But for the previous code I had posted (read-csv...), yes for that I need to convert to unix first for sbcl to read it well. I am gonna use TOKENIZE from now on and forget about file conversion. But maybe the sbcl guys porting it to windows should pay attention to that DOS/unix difference.
From: w_a_x_man on 9 Sep 2009 04:11 On Sep 8, 12:25 pm, Michael Weber <mw+goo...(a)foldr.org> wrote: > On Sep 8, 6:27 pm, Francogrex <fra...(a)grex.org> wrote: > > > ;;In ECL > > > > *MYCSV* > > > (("one" "two") ("three" "four") ("five" "six")) > > > ;;In SBCL it doesn't work well! > > *MYCSV* > > ") ("five" "six")) > > I can hardly believe that this is what sbcl printed. > > Anyway, perhaps you wanted DEFPARAMETER, because DEFVAR does not set > the variable's value if it is already bound. Also, I'd normally put > the DEFVAR/DEFPARAMETER on toplevel, like so: > > (defvar *mycsv* > (with-open-file ...)) > > Finally, with <http://foldr.org/~michaelw/lisp/tokenizer.lisp>: > > (defparameter *foo* > (with-open-file (s "test.csv") > (loop for line = (read-line s nil nil) while line > collect (tokenize line :delimiters #\, :whitespace t)))) > > *foo* > ==> (("one" "two") ("three" "four") ("five" "six")) Your output is wrong. Should be (("one" "two") ("three" "four" "") ("five" "six")) By the way, CSV files can be more comples than this--- can, in fact, contain binary data. If the two fields are foo,bar He said "What?" Then the CSV record is "foo,bar","He said ""What?""" So your program doesn't even begin to handle CSV files. For the trivial data given, this will do. IO.foreach("test.csv"){|s| p s.strip.split( ",", -1) }
First
|
Prev
|
Pages: 1 2 Prev: Dave's difficulties with manual activities Next: Lisp job available in Sydney, Australia |