Re: A style question
- From: "John Thingstad" <john.thingstad@xxxxxxxxx>
- Date: Wed, 28 Feb 2007 11:40:20 +0100
On Wed, 28 Feb 2007 03:02:46 +0100, <job-271842874@xxxxxxxxxxxxxx> wrote:
Frank Buss wrote:job-271842874@xxxxxxxxxxxxxx wrote:
I cranked out a Lisp version. It seems a bit clunky, so I thought I'd see if anyone had suggestions for improvements.looks ok, but I would use loop and organize the body of the loop a bit
different:
(defun fizz-buzz (n)
(loop for i from 1 to n
for fizz = (zerop (mod i 3))
for buzz = (zerop (mod i 5)) do
(when fizz (princ "Fizz"))
(when buzz (princ "Buzz"))
(when (not (or fizz buzz)) (princ i))
(terpri)))
Thanks. Some questions/comments:
1) In "ANSI Common Lisp", Graham makes the following comments:
"The loop macro was originally designed to help inexperienced Lisp users write iterative code...Unfortunately, loop is more like English than its designers ever intended...to understand it in the abstract is almost impossible...For such reasons, the use of loop cannot be recommended."
You will find the same recommendation from Peter Norwig in "Paradigms of AI programming".
Something along the line: 'loop has a syntax that looks like English, unfortunately
it is nothing like English.
This is true.
For many years most lispers avoided loop. (except simplified loop)
I think the description in the ANSI CL standard entry on 'loop is next to
unreadable. This is probably the real reason it wasn't used.
What you need to learn 'loop is tons of examples.
Then along came Peter Seibels book "Practical Common Lisp"
in particular the chapter "Loop for black belts".
I know it taught me 'loop as it probably did most of the people here.
Yes 'loop's syntax is not intuitive (though highly readable).
In my opinion it's power makes it worth while to learn.
Whether you use it or not is a matter of taste.
There are other alternatives.
There is always 'do or there is a iterator package.
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
.
- References:
- A style question
- From: job-271842874
- Re: A style question
- From: Frank Buss
- Re: A style question
- From: job-271842874
- A style question
- Prev by Date: Re: A style question
- Next by Date: Re: A style question
- Previous by thread: Re: A style question
- Next by thread: Re: A style question
- Index(es):
Relevant Pages
|
|