Re: A style question
- From: Ken Tilton <kentilton@xxxxxxxxx>
- Date: Tue, 27 Feb 2007 22:18:23 -0500
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."
Is this a minority view? One of the things that attracted me to Lisp was the simplicity, consistency, etc. of the language, so when I read the above, it seemed reasonable.
I was anti-loop bigot for years, now I cannot even remember the syntax of dolist. PG is a closet Schemer. Look at Arc. Pure minimalist. He does not like CLOS either. Now it may be that /you/ are a latent Schemer and that would be fine, but the spirit of Common Lisp is the more mud the better. LOOP rocks.
2) Thanks for the zerop tip. I like (zerop (mod m n)) better than (= 0 (mod m n))
3) Any reason why you chose (when fizz (princ "Fizz")) instead of (if fizz (princ "Fizz")) ?
4) Curious about the history of "terpri" - I guess it's shorter than "newline" but not very intuitive :)
I'm really enjoying learning Lisp. I realize at this stage I still have some "the grass is greener" and "oh cool, something new to learn!" influences, but I expect as that wears off the merits of the language will continue to shine through.
It does not wear off:
http://wiki.alu.org/RtL_Highlight_Film
Now get to work:
http://wiki.alu.org/The_Road_to_Lisp_Survey
Anybody want to let me know about Roads they have added over the past years that never made it to the highlight film? I mean, it /is/ a wiki, but I would be happy to play editor and pick out the sound bites from anyone not yet in the highlight film.
kzo
--
Well, I've wrestled with reality for 35 years, Doctor, and
I'm happy to state I finally won out over it.
-- Elwood P. Dowd
In this world, you must be oh so smart or oh so pleasant.
-- Elwood's Mom
.
- 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
|