Re: reading file to list



On Jan 17, 7:07 pm, André Thieme <address.good.until.
2009.may...@xxxxxxxxxxx> wrote:
K Livingston schrieb:



On Jan 17, 2:30 pm, André Thieme <address.good.until.
2009.may...@xxxxxxxxxxx> wrote:
And btw, Drew Krause is just a Lisp newbie. No Lisper would ever store
data for his programs in the format
3 10 2
4 1
11 18

but instead as
(3 10 2)
(4 1)
(11 18)

Maybe he doesn't get to designate the format he has to read?

But really, why wouldn't a Lisper consider that format?  If it really
is just sequences of numbers you're just adding a lot of funny
parenthesis in your data file, making it larger for no good reason,
when you already have delimiters.

If it were really like that, if those parenthesis would be there for
no good reason, then it would make no sense, I agree.
But they are there for a reason.
Their presence makes it easier to read them back.
No splitting needed, no conversion to integers, not two mappings.


The read-delimited-list solution above works in a single pass and is
not hindered in the slightest by the absence of parentheses. (and
it's only a few lines of code)


And writing out the data is also trivial.

for the data format above mapping
(format stream "~{~S~^ ~}~%" list-of-numbers)
seems pretty trivial.

or if you really want it in one line
(format stream "~:{~@{~S~^ ~}~%~}" list-of-list-of-numbers)


Anyway, all I've been trying to point out is that the absence or
presence of parentheses has pretty much no bearing on ones ability to
read, manipulate, or print data. (The belief that it does comes up
often.) For the most part any straightforward data format is as
trivial as any other to do whatever you want with. The lisp reader by
default reads s-expressions, but that doesn't mean that's all you can
input in lisp. A few tweaks here or there to the reader covers most
of the cases I've ever seen. CommonLisp gives you a lot of power by
exposing all these tools to you, and I, for one, would rather go back
to my toolbox and pick up my screwdriver, than sit there hammer in
hand and say "why are all these screws in my way."

-Kevin
.



Relevant Pages

  • Re: Pickle Problem
    ... Here's the code I'm stuck on ... format, but you don't open the file in binary mode. ... Sure enough, it was the parenthesis. ... about the binary format for opening files. ...
    (comp.lang.python)
  • Re: Parsing a chemical formal
    ... > Abigail wrote: ... ;-) Actually it's not an exercise, the perlscript should format Database ... > parenthesis: for instance Fe3. ... You can do this by first capturing ...
    (comp.lang.perl.misc)
  • Re: How do i find and replace words in parenthesis?
    ... it will say Format: Font ... find and replace with special characters, ... letters and numbers enclosed in parenthesis (including the ...
    (microsoft.public.word.docmanagement)
  • Re: Phone number format
    ... > Access calls it a "mask" but in Filemaker8, is it possible to format ... > a field to make phone numbers appear with parenthesis and hyphen in ... This calculation comes from the custom functions library at ... If there are too few characters, it formats the text in red. ...
    (comp.databases.filemaker)
  • Re: Nested parens are driving me nuts
    ... >parenthesis are probably the reason. ... Get better at Algebra ?:-) ...
    (sci.electronics.cad)