Author: Steven Edwards
Date: 20:27:49 03/25/04
Go up one level in this thread
On March 25, 2004 at 08:43:30, Tord Romstad wrote:
>On March 25, 2004 at 08:17:43, Steven Edwards wrote:
>>The Common Lisp spec for "loop" is far worse than "format". It is a fine
>>example of why programming languages should NOT be designed by committee.
>>(ChessLisp has no "loop" intrinsic.)
>
>I happen to like the LOOP macro a lot, although I admit that it tends to look
>ugly when people overuse the more advanced features.
It's a case of too much rope, as the saying goes. Alas, it's often those with
the lesser experience whose overuse creates hard-to-read and harder-to-debug
code.
>I regard DO (like TAGBODY and UNWIND-PROTECT) as mainly a low-level construct
>which is sometimes useful for building more high-level macros, it is not
>something I want to see as part of normal code. LOOP, if used wisely, is
>much prettier and easier to read.
I manage to avoid the general "do" (and also the "go" intrinsic) and I can't
think of a single time that this policy has cramped my Lisp coding.
>The below example from the HyperSpec is a nice example. I find it hard
>to see how you could write the same code as readable and clear as this
>with any of the other built-in looping constructs.
>
>;; Another example of the extended form of LOOP.
> (loop for n from 1 to 10
> when (oddp n)
> collect n)
>=> (1 3 5 7 9)
Or:
(let ((Result nil))
(dotimes (Index 10)
(when (odd? Index) (push Index Result)))
(reverse Result))
(1 3 5 7 9)
Which is preferable to me as:
1. I like to have every index loop: A) start at zero, and B) have an iteration
count fixed at loop entry. Simple is good.
2. I like to have explicit accumulators as they often make debugging easier.
3. "when" is solely a simple macro name and not also a keyword.
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.