From: Rob Warnock on
Harald Hanche-Olsen <hanche(a)math.ntnu.no> wrote:
+---------------
| + Harald Hanche-Olsen <hanche(a)math.ntnu.no>:
| | for fizz in '#3=(nil nil "Fizz" . #3#)
| | for buzz in '#5=(nil nil nil nil "Buzz" . #5#)
|
| But I hadn't read the whole thread and missed Rob Warnock's use of
| this same trick in <zZSdnVArCY40vHjYnZ2dnUVZ_ruknZ2d(a)speakeasy.net>.
+---------------

But yours is neater [== hackier], since it uses the actual non-NIL
generalized boolean values. Mine just used T & NIL in the circular
lists and had to provide the "Fizz" and "Buzz" elsewhere...


-Rob

-----
Rob Warnock <rpw3(a)rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607

From: John Thingstad on
On Thu, 01 Mar 2007 04:19:08 +0100, lojic <lojicdotcom(a)gmail.com> wrote:

> On Feb 28, 5:39 pm, t...(a)sevak.isi.edu (Thomas A. Russ) wrote:
>> Well, OK -- I have gone into the West, but I stopped just short of the
>> Pacific Ocean. Obviously this requires some finesse since we don't want
>> to have to specify arguments more than once. So we do need to obscurely
>> move back and forth along the argument list:
>>
>> (dotimes (i 20)
>> (format t "~[Fizz~:;~]~[Buzz~*~:;~2:*~[~2*~:;~*~D~]~]~%"
>> (mod i 3) (mod i 5) i))
>>
>> Now this is just way too obscure for me -- and it looks vaguely like
>> Perl code ;)
>
> Disturbing yet impressive. Anyone want to give a hand to the newbie in
> understanding the above?
>
> Brian
>

Shouldn't be necessary. The key to this cypher is in
the ANSI document under format options.

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
From: Vassil Nikolov on

On Wed, 28 Feb 2007 14:48:27 +0100, Rainer Joswig <joswig(a)lisp.de> said:
| ...
| Take this (not written by me).

Zmacs?

| ...
| How about this? This is clearly from aliens.

But was ported to Common Lisp at some point, wasn't it?

---Vassil.


--
mind mate, n.
One of two persons mentally compatible with each other (cf. soul mate).
From: Rob Warnock on
<nallen05(a)gmail.com> wrote:
+---------------
| Rob Warnock wrote:
| > This one is both efficient -- *no* MOD calls at all! --
| > *and* so ugly only a parent could love it: ;-} ;-}
| >
| > (defun fizz-buzz (n)
| > (loop for i from 1 to n
| > and three-p in '#3=(nil nil t . #3#)
| > and five-p in '#5=(nil nil nil nil t . #5#)
| > do ...
|
| This is awsome, Rob ;-) But I can make one that's faster AND uglier!
|
| (defmacro def-fizz-buzz ()
| (let (l)
| (do* ((i 1 (incf i))
| (m3p (zerop (mod i 3))
| (zerop (mod i 3)))
| (m5p (zerop (mod i 5))
| (zerop (mod i 5))))
| ((> i 15))
| (setq l
| (list* `(print ,(cond ((and m3p m5p) "FizzBuzz")
| (m3p "Buzz")
| (m5p "Fizz")
| (t 'y)))
| '(when (> y x) (return))
| '(incf y)
| l)))
| `(defun fizz-buzz (x)
| (let ((y 0))
| (loop ,@(reverse l))))))
+---------------

Yes!! *That's* how to use macros to write code for you!! ;-}

One minor tweak -- instead of:

(INCF Y)
(WHEN (> Y X) (RETURN))

you could use:

(WHEN (> (INCF Y) X) (RETURN))

Another really minor tweak -- in the DO* variable bindings,
instead of (M3P (ZEROP (MOD I 3)) (ZEROP (MOD I 3)) you can
write (M3P #1=(ZEROP (MOD I 3)) #1#).

Now for *lots* of extra credit... ;-} ;-}

Write the general version of DEF-FIZZ-BUZZ that accepts a
function name (so we can tell them apart) and an alist of primes
and strings, and emits similarly-correct/fast code. E.g., the
example we've been using all along would be generated like so:

(def-fizz-buzz 'fizz-buzz '((3 "Fizz") (5 "Buzz")))


-Rob

-----
Rob Warnock <rpw3(a)rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607

From: lojic on
On Feb 28, 11:29 pm, r...(a)rpw3.org (Rob Warnock) wrote:
> Now for *lots* of extra credit... ;-} ;-}
>
> Write the general version of DEF-FIZZ-BUZZ that accepts a
> function name (so we can tell them apart) and an alist of primes
> and strings, and emits similarly-correct/fast code. E.g., the
> example we've been using all along would be generated like so:
>
> (def-fizz-buzz 'fizz-buzz '((3 "Fizz") (5 "Buzz")))

That goes back to my earlier post of the following generalized
solution:

(defun fizz-buzz (n lst)
(do ((i 1 (+ i 1)))
((> i n))
(let
((fizzed nil))
(dolist (obj lst)
(let ((a (car obj))
(str (car (cdr obj))))
(when (zerop (mod i a))
(princ str)
(setf fizzed t))))
(if (not fizzed)
(princ i))
(terpri))))

(fizz-buzz 15 '((3 "Fizz") (5 "Buzz")))

This was my off-the-cuff approach from a non-Lisp background. I would
like to see a macro-ized version and get some feedback from the group
regarding the appropriateness of macros in this case vs. a simple
function as in the above.

Brian Adkins

>
> -Rob
>
> -----
> Rob Warnock <r...(a)rpw3.org>
> 627 26th Avenue <URL:http://rpw3.org/>
> San Mateo, CA 94403 (650)572-2607