[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: lisp idiom for processing each line in a file?

William James

10/15/2015 6:19:00 AM

Rob Warnock wrote:

> (with-open-file (stream "../../words/test.txt")
> (loop for line = (read-line stream nil nil)
> while line do
> (per-line-fn line)))


Gauche Scheme:

(with-input-from-file "tmp.txt"
(cut generator-for-each
per-line-fn
read-line))


>
> +---------------
> | Is there a simpler way of doing what I'm trying to do here?
> +---------------
>
> See above.
>
> +---------------
> | I've seen some loop-based solutions, but am staying away from
> | loop for the moment.
> +---------------
>
> Why?!? It's the most natural way to code this particular task, IMHO.

Note how he preciously indicates consternation, dismay,
disbelief, and disgust by the use of "?!?".

He simply cannot stand it that there are those who don't
worship his chthonic deities, CL (COBOL-Like) and LOOP.

----------

Paul Graham:

I consider Loop one of the worst flaws in CL, and an example
to be borne in mind by both macro writers and language designers.

[ In "ANSI Common Lisp", Graham makes the following comments: ]

The loop macro was originally designed to help inexperienced
Lisp users write iterative code. Instead of writing Lisp code,
you express your program in a form meant to resemble English,
and this is then translated into Lisp. Unfortunately, loop is
more like English than its designers ever intended: you can
use it in simple cases without quite understanding how it
works, but to understand it in the abstract is almost
impossible.
....
the ANSI standard does not really give a formal specification
of its behavior.
....
The first thing one notices about the loop macro is that it
has syntax. A loop expression contains not subexpressions but
clauses. The clauses are not delimited by parentheses;
instead, each kind has a distinct syntax. In that, loop
resembles traditional Algol-like languages. But the other
distinctive feature of loop, which makes it as unlike Algol as
Lisp, is that the order in which things happen is only
loosely related to the order in which the clauses occur.
....
For such reasons, the use of loop cannot be recommended.


Dan Weinreb, one of the designers of Common Lisp:

.... the problem with LOOP was that it turned out to be hard to
predict what it would do, when you started using a lot of
different facets of LOOP all together. This is a serious problem
since the whole idea of LOOP was to let you use many facets
together; if you're not doing that, LOOP is overkill.



Barry Margolin, 05 Apr 2001
(http://groups.google.com/group/comp.lang.lisp/msg/8a48ce...)

>(My second rule of thumb concerning LOOP would be the negative of
>Barry Margolin's: The more complex the looping, the more you need/want
>to use LOOP.)

My recommendation is based on seeing many question in the past of the form
"What happens if you use both XXX and YYY in the same LOOP?" The
unfortunate fact is that when we were writing the standard we didn't have
time to nail down all the possible interactions between different LOOP
features, so many of these are not well specified. And even if we did get
it right in the standard, it's likely to be difficult to find them and I
wouldn't trust that all implementors got it right (many of those questions
were probably from implementors, trying to figure out what they were
supposed to do). And even if they all got it right, someone reading your
code may not be able to figure it out.

So, with all those potential problems, my feeling is that if you have to
ask, it's probably better to use something other than LOOP.



Barry Margolin:

> 3. Loop is very powerful, granted, and many people are trying to
> argue that "you can do so much with loop that it's unreadable."
> This is not an argument.

But it is! Because any use of LOOP has the potential to be
unreadable, the reader must read it carefully to verify that
it's just one of the cases that doesn't require careful
reading!


From: John Foderaro <jkf@unspamx.franz.com>
Newsgroups: comp.lang.lisp
Subject: Re: the "loop" macro
Date: Sun, 26 Aug 2001 10:51:26 -0700

I'm not trying to join a debate on loop. I just wanted to present
the other side of [the issue so that] the intelligent people can
then weigh the arguments on both sides.

I'm not suggesting that loop can be fixed either by adding
parenthesis or coming up with ways of indenting it to make it
understandable. It's a lost cause.

----------


Worshippers of CL (COBOL-Like) hate recursion and every form of
Lispy programming. They even hate McCarthy, the inventor of of
Lisp. He insisted that "Lisp" should not be use as a synonym
for CL (COBOL-Like), but CL-worshippers do it all of the time.

They are the vilest and the worst enemies that Lisp has
ever had.

--
In Stockholm ... 20 Muslim men ... began to assault the children, ripping their
swimsuits off.... [T]he men cornered one of the [11-year-old] girls in a
grotto in the bathhouse and gang-raped her. The police refused to press any
charges. www.liveleak.com/view?i=807_1369627137
1 Answer

William James

10/15/2015 6:34:00 AM

0

WJ wrote:

> Rob Warnock wrote:
>
> > (with-open-file (stream "../../words/test.txt")
> > (loop for line = (read-line stream nil nil)
> > while line do
> > (per-line-fn line)))
>
>
> Gauche Scheme:
>
> (with-input-from-file "tmp.txt"
> (cut generator-for-each
> per-line-fn
> read-line))
>
>
> >
> > +---------------
> > > Is there a simpler way of doing what I'm trying to do here?
> > +---------------
> >
> > See above.
> >
> > +---------------
> > > I've seen some loop-based solutions, but am staying away from
> > > loop for the moment.
> > +---------------
> >
> > Why?!? It's the most natural way to code this particular task, IMHO.
>
> Note how he preciously indicates consternation, dismay,
> disbelief, and disgust by the use of "?!?".
>
> He simply cannot stand it that there are those who don't
> worship his chthonic deities, CL (COBOL-Like) and LOOP.
>
> ----------
>
> Paul Graham:
>
> I consider Loop one of the worst flaws in CL, and an example
> to be borne in mind by both macro writers and language designers.
>
> [ In "ANSI Common Lisp", Graham makes the following comments: ]
>
> The loop macro was originally designed to help inexperienced
> Lisp users write iterative code. Instead of writing Lisp code,
> you express your program in a form meant to resemble English,
> and this is then translated into Lisp. Unfortunately, loop is
> more like English than its designers ever intended: you can
> use it in simple cases without quite understanding how it
> works, but to understand it in the abstract is almost
> impossible.
> ....
> the ANSI standard does not really give a formal specification
> of its behavior.
> ....
> The first thing one notices about the loop macro is that it
> has syntax. A loop expression contains not subexpressions but
> clauses. The clauses are not delimited by parentheses;
> instead, each kind has a distinct syntax. In that, loop
> resembles traditional Algol-like languages. But the other
> distinctive feature of loop, which makes it as unlike Algol as
> Lisp, is that the order in which things happen is only
> loosely related to the order in which the clauses occur.
> ....
> For such reasons, the use of loop cannot be recommended.
>
>
> Dan Weinreb, one of the designers of Common Lisp:
>
> ... the problem with LOOP was that it turned out to be hard to
> predict what it would do, when you started using a lot of
> different facets of LOOP all together. This is a serious problem
> since the whole idea of LOOP was to let you use many facets
> together; if you're not doing that, LOOP is overkill.
>
>
>
> Barry Margolin, 05 Apr 2001
> (http://groups.google.com/group/comp.lang.lisp/msg/8a48ce...)
>
> > (My second rule of thumb concerning LOOP would be the negative of
> > Barry Margolin's: The more complex the looping, the more you need/want
> > to use LOOP.)
>
> My recommendation is based on seeing many question in the past of the form
> "What happens if you use both XXX and YYY in the same LOOP?" The
> unfortunate fact is that when we were writing the standard we didn't have
> time to nail down all the possible interactions between different LOOP
> features, so many of these are not well specified. And even if we did get
> it right in the standard, it's likely to be difficult to find them and I
> wouldn't trust that all implementors got it right (many of those questions
> were probably from implementors, trying to figure out what they were
> supposed to do). And even if they all got it right, someone reading your
> code may not be able to figure it out.
>
> So, with all those potential problems, my feeling is that if you have to
> ask, it's probably better to use something other than LOOP.
>
>
>
> Barry Margolin:
>
> > 3. Loop is very powerful, granted, and many people are trying to
> > argue that "you can do so much with loop that it's unreadable."
> > This is not an argument.
>
> But it is! Because any use of LOOP has the potential to be
> unreadable, the reader must read it carefully to verify that
> it's just one of the cases that doesn't require careful
> reading!
>
>
> From: John Foderaro <jkf@unspamx.franz.com>
> Newsgroups: comp.lang.lisp
> Subject: Re: the "loop" macro
> Date: Sun, 26 Aug 2001 10:51:26 -0700
>
> I'm not trying to join a debate on loop. I just wanted to present
> the other side of [the issue so that] the intelligent people can
> then weigh the arguments on both sides.
>
> I'm not suggesting that loop can be fixed either by adding
> parenthesis or coming up with ways of indenting it to make it
> understandable. It's a lost cause.
>
> ----------
>
>
> Worshippers of CL (COBOL-Like) hate recursion and every form of
> Lispy programming. They even hate McCarthy, the inventor of of
> Lisp. He insisted that "Lisp" should not be use as a synonym
> for CL (COBOL-Like), but CL-worshippers do it all of the time.
>
> They are the vilest and the worst enemies that Lisp has
> ever had.


MatzLisp (Ruby):

IO.foreach("tmp.txt"){|line| puts line}

Another way:

IO.foreach("tmp.txt").each &:display

--
Africans gang-rape and clitorectomize Finnish girl; government arrests Finn
whom they accuse of complaining:
conservative-headlines.com/2009/03/another-european-awaits-extradition-for-hate-speech