LISP style question - (with-open-file)
- From: ccc31807 <cartercc@xxxxxxxxx>
- Date: Tue, 29 May 2012 07:59:55 -0700 (PDT)
I've read that a C programmer will write LISP as C. as i recall that
is attributed to Paul Graham. I seem to be in that category (except
I'm using Perl). I can't figure out what a proper style for LISP is
(or maybe there isn't and I'm just thinking that there is).
This involves the very common Perl task of munging data -- opening
files as input to read data, grabbing the data and manipulating it,
and opening files as output to write data. Here is a skeleton of some
typical Perl template that opens two files for input and opens tow
files for output:
my (%data_hash_in, %data_hash_out);
open IN1, '<', 'firstinput.txt';
while (<IN1>)
{
first_stuff_data_into_hash(); #using %data_hash_in
}
close IN1;
open IN2, '<', 'secondinput.txt';
while (<IN2>)
{
second_stuff_data_into_hash(); #using %data_hash_in
}
close IN2;
%data_hash_out = munge_data(%data_hash_in);
open OUT1, '>', 'csvoutput.csv';
open OUT2, '>', 'pdfoutput.pdf';
foreach my $key (sort keys %data_hash_out)
{
print_to_csv($data_hash_out{$key});
print_to_pdf($data_hash_out{$key});
}
close OUT1;
close OUT2;
exit(0);
The LISP template that I'm attempting to use looks something like
this:
(with-open-file
(open-and-read-file-1)
(with-open-file
(open-and-read-file-2)
(with-open-file
(open-and-print-to-file-3)
(with-open-file
(open-and-print-to-file-4)))))
My mental image of Perl is a sequential set of steps, called one after
another, processing lines iteratively. My mental image of LISP is an
outer function calling inner functions processing lines recursively.
Either this is an incorrect mental image of LISP or I'm not yet
equipped to write in proper LISP style (most likely).
What would be an appropriate style for the case of opening two files
(say, a students file and a classes file), mashing the data together
(with the students info and the classes info and the class), and
writing to two output files (say, a report cards file as a PDF and a
statistical analysis file in CSV)?
Thanks, CC.
.
- Follow-Ups:
- Re: LISP style question - (with-open-file)
- From: Zach Beane
- Re: LISP style question - (with-open-file)
- From: Madhu
- Re: LISP style question - (with-open-file)
- From: Sam Steingold
- Re: LISP style question - (with-open-file)
- From: Barry Margolin
- Re: LISP style question - (with-open-file)
- From: Norbert_Paul
- Re: LISP style question - (with-open-file)
- Prev by Date: generic files + persistent binary search trees
- Next by Date: Re: LISP style question - (with-open-file)
- Previous by thread: generic files + persistent binary search trees
- Next by thread: Re: LISP style question - (with-open-file)
- Index(es):
Relevant Pages
|