Re: A style question



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)))

--
Frank Buss, fb@xxxxxxxxxxxxx
http://www.frank-buss.de, http://www.it4-systems.de
.



Relevant Pages

  • Re: Format puzzle
    ... (loop for tail on list ... collect (list (first tail) ... do (princ (first tail) s) ...
    (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: A style question
    ... but I would use loop and organize the body of the loop a bit ... (when fizz (princ "Fizz")) ... In "ANSI Common Lisp", ... 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. ...
    (comp.lang.lisp)
  • Re: Break Statements similar to C or C++
    ... There's no built-in while loop in cl, but you can build one with ... Here's an example with the loop macro ... else do (princ i)) ...
    (comp.lang.lisp)
  • Re: List of digits->number
    ... (multiple-value-bind (quotient remainder) ... LOOP is ok, but I wonder if there is a more elegant contruct like REDUCE ... Frank Buss, fb@xxxxxxxxxxxxx ...
    (comp.lang.lisp)