From: lojic on
On Feb 28, 3:24 am, Rainer Joswig <jos...(a)lisp.de> wrote:
> > (defun fizz-buzz (n)
> > (do ((i 1 (+ i 1))) ((> i n))
> > (let
> > ((fizz (zerop (mod i 3)))
> > (buzz (zerop (mod i 5))))
> > (when fizz (princ "Fizz"))
> > (when buzz (princ "Buzz"))
> > (format t "~A~%" (if (or fizz buzz) "" i)))))
>
> In DO you can have more than one clauses for iteration.
> So you could get rid of the extra LET.

Isn't let required to set the fizz and buzz local vars within the
loop?

Brian

From: lojic on
On Feb 28, 5:33 am, "Tim Bradshaw" <tfb+goo...(a)tfeb.org> wrote:
> On Feb 28, 2:02 am, job-271842...(a)craigslist.org wrote:
> > 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.
>
> Simplicity? consistency? I think you're thinking of some other
> language there. CL is this vast industrial thing full of enormous
> machines, oil and rust.

I was referring to the syntax in particular e.g. (foo a b) and the
fact that the syntax makes it easier to generate and manipulate Lisp
code.

> Some compartments are full of water, and no
> one knows what some of the machines do, if anything. Many parts of it
> use a mixture of Whitworth & BSF threads (some left-handed), though
> much has now been converted to BA or metric, sometimes by use of taps
> & dies, sometimes with a hammer.
>
> CL's closest living relative is FORTRAN: always remember that.
>
> Incidentally, I'm deeply disappointed in the quality of answers in
> this thread. In the elder days there would have been at least a few
> followups showing how to do this in the proper "FORMAT string
> indistinguishable from line noise" way. No true CL programmer ever
> uses any other construct when the problem can be solved with a
> combination of FORMAT, LOOP & GO (FORMAT being always preferable,
> obviously). There may yet be those reading cll who know this, though
> I suspect they have all gone into the west now.
>
> --tim (who has used the FORMAT string mentioned inhttp://www.tfeb.org/lisp/obscurities.htmlin anger)


From: lojic on
On Feb 28, 10:51 am, "justinhj" <justi...(a)gmail.com> wrote:
> On Feb 27, 11:31 pm, job-271842...(a)craigslist.org wrote:
>
>
>
> > justinhj wrote:
> > > (defun multiple(x n)
> > > (= 0 (mod x n)))
>
> > > (defun output-multiple(x n str)
> > > (if (and (multiple x n) (princ str))
> > > 1
> > > 0))
>
> > > (defun fizzbuzz(n)
> > > (loop for x from 1 to n do
> > > (if (> (+ (output-multiple x 3 "fizz") (output-multiple x 5
> > > "buzz")) 0)
> > > (format t "~%"))))
>
> > Hmm.. this doesn't seem to work.
>
> > [1]> (defun multiple(x n)
> > (= 0 (mod x n)))
> > MULTIPLE
> > [2]>
> > (defun output-multiple(x n str)
> > (if (and (multiple x n) (princ str))
> > 1
> > 0))
> > OUTPUT-MULTIPLE
> > [3]>
> > (defun fizzbuzz(n)
> > (loop for x from 1 to n do
> > (if (> (+ (output-multiple x 3 "fizz") (output-multiple x 5
> > "buzz")) 0)
> > (format t "~%"))))
> > FIZZBUZZ
> > [4]> (fizzbuzz 12)
> > fizz
> > buzz
> > fizz
> > fizz
> > buzz
> > fizz
> > NIL
> > [5]>
>
> Unless I'm misunderstanding something what doesn't work? The output is
> correct.
>
> Justin

The output should be:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
....

From: lojic on
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

From: Rob Warnock on
Pillsy <pillsbury(a)gmail.com> wrote:
+---------------
| Ken Tilton <kentil...(a)gmail.com> wrote:
| > Tim Bradshaw wrote:
| [...]
| > > Incidentally, I'm deeply disappointed in the quality of answers in
| > > this thread. In the elder days there would have been at least a few
| > > followups showing how to do this in the proper "FORMAT string
| > > indistinguishable from line noise" way.
|
| > Oh, absolutely, long overdue in this thread. Is this going to become a
| > lost art? The village elders need to step up, methinks. I started
| > playing with it, but I am just an elder, not a Lisp elder. Screams for a
| > nested thingy, yes?
|
| Well, if you're going to throw down the gauntlet like that, I'm
| just going to have to respond in the hopes of provoking someone
| into besting my wimpy attempt.
|
| (apply #'format t "~@{ ~2@{~D ~}~^~*Fizz ~D ~*Buzz~
| ~*Fizz ~2@{~D ~} ~*Buzz ~D ~*Fizz~
| ~2@{~D ~} ~*FizzBuzz ~%~}"
| (loop :for i :from 1 to 100 :collect i))
+---------------

Very cute!! Except... it doesn't give correct answers:

1 2 Fizz 4 BuzzFizz 7 8 Buzz 10 Fizz12 13 FizzBuzz
15 16 Fizz 18 BuzzFizz 21 22 Buzz 24 Fizz26 27 FizzBuzz
29 30 Fizz 32 BuzzFizz 35 36 Buzz 38 Fizz40 41 FizzBuzz
43 44 Fizz 46 BuzzFizz 49 50 Buzz 52 Fizz54 55 FizzBuzz
57 58 Fizz 60 BuzzFizz 63 64 Buzz 66 Fizz68 69 FizzBuzz
71 72 Fizz 74 BuzzFizz 77 78 Buzz 80 Fizz82 83 FizzBuzz
85 86 Fizz 88 BuzzFizz 91 92 Buzz 94 Fizz96 97 FizzBuzz
99 100

- Those "BuzzFizz" should probably be "Buzz Fizz" (missing space).
- Missing spaces elsewhere, too.
- 9 is divisible by 3, not 5.
- 11 is *not* divisible by either 3 or 5.
- 12 *is* divisible by 3.
- 14 is *not* divisible by 3.
- Etc. etc...


-Rob

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