help-gnu-emacs
[Top][All Lists]
Advanced

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

RE: loop macro tutorial


From: Drew Adams
Subject: RE: loop macro tutorial
Date: Wed, 17 Jun 2009 10:20:41 -0700

> > C-h f loop does not tell me anything.
> > Do You know any sites that would explain 'loop' in more clear way?
> 
> It comes from CLtL LOOP, which we find in Common Lisp too:
> 
>    http://www.lispworks.com/reference/HyperSpec/Body/m_loop.htm
>    http://www.lispworks.com/documentation/HyperSpec/Body/06_a.htm
>    http://www.gigamonkeys.com/book/loop-for-black-belts.html


Yes, but don't loop; iterate:

http://common-lisp.net/project/iterate/doc/Don_0027t-Loop-Iterate.html
http://common-lisp.net/project/iterate/doc/index.html#Top

>From "Don't Loop, Iterate":

"`loop''s Pascalish syntax creates several problems.

1. First, many dyed-in-the-wool Lisp hackers simply find it ugly.

2. Second, it requires learning the syntax of a whole new sublanguage.

3. Third, the absence of parens makes it hard to parse, both by machine and,
more importantly, by human.

4. Fourth, one often has to consult the manual to recall lesser-used aspects of
the strange syntax.

5. Fifth, there is no good interface with the rest of Lisp, so `loop' clauses
cannot appear inside Lisp forms, and macros cannot expand to pieces of `loop'.

6. Sixth, pretty-printers and indenters that don't know about `loop' will
invariably display it wrongly.

This [6] is particularly a problem with program-editor indenters. A reasonably
clever indenter, like that of Gnu Emacs, can indent nearly any normal Lisp form
correctly, and can be easily customized for most new forms. But it can't at
present handle `loop'. The syntax of `iterate' was designed to keep parens to a
minimum, but conform close enough to Lisp so as not to confuse code-display
tools. Gnu Emacs indents `iterate' reasonably with no modifications.

Indenting is a mere annoyance; `loop''s lack of extensibility is a more serious
problem. The original `loop' was completely extensible, but the Symbolics
version only provides for the definition of new iteration-driving clauses, and
the Common Lisp specification does not have any extension mechanism."

(On the flip side, `loop' is built into Common Lisp, including the
byte-compiler. `iterate' is not.)

No, I don't know of an Emacs-Lisp implementation of `iterate'. But maybe the CL
implementation will work or can be made to work with Emacs Lisp's `cl.el'.
Dunno.

Personally, I use `while', `dolist', and `dotimes' (and `mapcar'...). ;-)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]