Re: reading file to list
- From: K Livingston <kevinlivingston.public@xxxxxxxxx>
- Date: Sat, 17 Jan 2009 19:10:23 -0800 (PST)
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
.
- References:
- reading file to list
- From: Drew Krause
- Re: reading file to list
- From: w_a_x_man
- Re: reading file to list
- From: William James
- Re: reading file to list
- From: K Livingston
- Re: reading file to list
- From: André Thieme
- reading file to list
- Prev by Date: Re: Rationale behind unwind-protect and double errors
- Next by Date: Re: CLISP bignum performance.
- Previous by thread: Re: reading file to list
- Next by thread: Re: reading file to list
- Index(es):
Relevant Pages
|