From: Lars Rune Nøstdal on
On Wed, 28 Feb 2007 02:08:39 +0000, Lars Rune Nøstdal wrote:

> (defmacro cond* (&body body)
> `(let ((any-clause-p nil))


Yup; I forgot the gensym:


(defmacro cond* (&body body)
(let ((any-clause-p (gensym)))
`(let ((,any-clause-p nil))
,@(mapcar (lambda (clause-form)
(if (eq :unless-till-now (first clause-form))
`(unless ,any-clause-p ,(second clause-form))
`(when ,(first clause-form)
,(second clause-form)
(setf ,any-clause-p t))))
body))))

--
Lars Rune Nøstdal
http://nostdal.org/
From: Wade Humeniuk on
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
From: Pillsy on
On Feb 27, 9:02 pm, job-271842...(a)craigslist.org wrote:
[...]
> 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?

I think it is. I cordially despise LOOP myself, but almost everyone
uses it for simple stuff some of the time. You can avoid it entirely
if you want, but it can make your life unneccessarily difficult do.

You should spend some time becoming familiar with it. At the very
least, you need a basic understanding to read other people's
code. Then you can make an informed decision to avoid it. :)

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

Common Lisp is in some ways simple, and pretty consistent, but it's
also huge and not particularly "pure". Personally, I like the sense of
compromise and age.

Others prefer Scheme, which is a different dialect of Lisp which is
all about being small and elegant and pure. I find it sterile and
spare and unfun myself.

> 3) Any reason why you chose (when fizz (princ "Fizz")) instead of (if
> fizz (princ "Fizz")) ?

It's a little bit of Common Lisp style. If you are only going to use
the true branch of the conditional, use "when", and if you're only
going to use the false branch, use "unless".

Hope you continue to have fun.

Cheers,
Pillsy

From: Thierry Pirot on
job-271842874 writes:

> (defun fizz-buzz (n)
> (do ((i 1 (+ i 1)))
> ((> i n))
> (let
> ((fizz (= 0 (mod i 3)))
> (buzz (= 0 (mod i 5))))
> (if fizz (format t "Fizz"))
> (if buzz (format t "Buzz"))
> (format t "~A~%"
> (if (or fizz buzz) "" i)))))
>
> (fizz-buzz 100)
>
In a more functional style, my 2 cents,

CL-USER> (defun printing (i)
(format t "~a~%"
(cond
((= 0 (mod i 3)) "Fizz")
((= 0 (mod i 5)) "Buzz")
(t i))))

CL-USER> (defun fb (i n)
(when (< i n)
(printing i)
(fb (1+ i) n)))

CL-USER> (fb 1 100)
--
Take it Easy Don't worry Be Happy

Thierry

�������o�o��������o�o��������o�o��������o�o��������o�o�������
From: Wade Humeniuk on
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