Re: A style question





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
.



Relevant Pages

  • How to Speed up Cellular Automata [was Re: How to speed up an OpenGL application?]
    ... In the loop you hit aref a dozen times, god knows what else, without an iota of optimization. ... Lisp does more by default, so if you need to write ... (if (zerop cell) ...
    (comp.lang.lisp)
  • Re: A style question
    ... "The loop macro was originally designed to help inexperienced Lisp ... than its designers ever intended...to understand it in the abstract is ... I started playing with it, but I am just an elder, not a Lisp elder. ...
    (comp.lang.lisp)
  • Re: A style question
    ... (loop for i from 1 to n ... (when fizz (princ "Fizz")) ... In "ANSI Common Lisp", ...
    (comp.lang.lisp)
  • Re: Very poor Lisp performance
    ... Observe LOOP, ... than many Lisp users, as LOOP is offensive to a percentage of Lisp ... >>> natural and programming languages have complicated grammars precisely ... do you agree that languages are evolving to be more concise? ...
    (comp.lang.lisp)
  • efficiently accumulating values
    ... do (loop as j from 0 to (1- n) ... do (let ((old (aref matrix i j))) ... acc (rec ni nj word acc) ... Is there an efficient way to accumulate values in lisp? ...
    (comp.lang.lisp)