Re: A style question



Wade Humeniuk wrote:
Another style

(defun fbv (n)
(or (remove nil (list (and (zerop (mod n 3)) "Fizz")
(and (zerop (mod n 5)) "Buzz")))
(list n)))


(defun fizz-buzz (n)
(loop for i from 1 to n do (format t "~{~A~}~%" (fbv i))))

Wade

And with a few macros,

;--- Part of a handy kit
(defun prinl (list)
(map nil 'princ list)
(terpri))

(defmacro over (i start end &body body)
`(loop for ,i from ,start to ,end do ,@body))
(defmacro no-nulls (&body tests)
`(remove nil (list ,@tests)))
;----------------------------------------------

(defun fbv (n)
(or (no-nulls
(and (zerop (mod n 3)) "Fizz")
(and (zerop (mod n 5)) "Buzz"))
(list n)))


(defun fizz-buzz (n)
(over i 1 n (prinl (fbv i))))

Wade
.



Relevant Pages