[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: loop macro



    Date: Wed, 5 Feb 86 12:01 EST
    From: Guy Steele <gls@THINK-AQUINAS.ARPA>

    Okay, now here is a different perspective on the LOOP problem.  I will play
    devil's advocate here and claim that the main purpose of LOOP is to
    duplicate the functionality of the sequence functions.  

Your message is interesting.  I remember that you advocated the
inclusion of the sequence functions partly because you wanted Lisp to
benefit from the good ideas in APL, and this message seems like a
further exposition of that idea.  But I don't think it's a good argument
against LOOP.  Bearing in mind that you're playing devil's advocate,
here are the problems:

(1) Your message later goes on to say "This isn't operating on
sequences, so I will render this as a DO loop."  This in no way
supports the original thesis!  Many simple examples of LOOP don't
operate on sequences:

  (loop for x from 3 to 6
        do (print x))

That a LOOP can be rendered as a DO doesn't prove much; it can also be
rendered as a PROG.  I never use DO any more.  Ever.  LOOP is clearer
than DO in all cases, as far as I'm concerned.  It certainly doesn't
prove that LOOP is being used to duplicate the functionality of the
sequence functions.

(2) It would indeed be nice if the cons-intensive examples you gave were
optimized into the equivalent iterative code.  As far as I'm concerned,
it's an axiom of LOOP design/redesign that such compilers are not
widespread, if indeed they exist at all.  The phrase "duplicate the
functionality" is only accurate if it implicitly means "but much
faster".  Any claim that Common Lisp should not have an improved
iteration construct because it is conceivable and theoretically possible
that such a compiler might exist ignores Common Lisp's goal of living in
the real world.  I agree that it would be interesting and valuable to
have such a compiler.

(3) Some people don't like having to use nameless internal functions to
do simple things.  We could remove DOLIST from the language, since any
DOLIST can be trivially turned into a MAPC.  But we don't.  So in some
cases where iteration is being used to do something that could be done
with sequence functions, some people consider the iterative style
preferable.

[I agree with MMcM that based on the amount of interest so far, it would
be helpful to have a special-interest mailing list for this topic.]