From: John Thingstad on
On Wed, 28 Feb 2007 03:02:46 +0100, <job-271842874(a)craigslist.org> wrote:

> Frank Buss wrote:
>> job-271842874(a)craigslist.org 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)))
>>
>
> 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."
>

You will find the same recommendation from Peter Norwig in "Paradigms of
AI programming".
Something along the line: 'loop has a syntax that looks like English,
unfortunately
it is nothing like English.

This is true.
For many years most lispers avoided loop. (except simplified loop)

I think the description in the ANSI CL standard entry on 'loop is next to
unreadable. This is probably the real reason it wasn't used.
What you need to learn 'loop is tons of examples.

Then along came Peter Seibels book "Practical Common Lisp"
in particular the chapter "Loop for black belts".
I know it taught me 'loop as it probably did most of the people here.
Yes 'loop's syntax is not intuitive (though highly readable).
In my opinion it's power makes it worth while to learn.

Whether you use it or not is a matter of taste.
There are other alternatives.
There is always 'do or there is a iterator package.

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
From: Rainer Joswig on
In article <1172658813.746823.247380(a)p10g2000cwp.googlegroups.com>,
"Tim Bradshaw" <tfb+google(a)tfeb.org> wrote:

> On Feb 28, 2:02 am, job-271842...(a)craigslist.org wrote:
>
> >
> > 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."
>
> Reading Paul Graham is a bit like reading reviews of films by a good
> critic: he is almost always wrong about everything, but has
> interesting things to say and it's possible to reliably predict
> whether you'll like something from what he says about it (though often
> you will differ from him on whether you like it, due to the above-
> mentioned almost-always-being-wrong thing). He's kind of the Barry
> Norman of Lisp, really.

I agree. ;-)

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

Common Lisp is a bit of the alligator in the pond, eating all
the younger designs. ;-)

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

It is always a shock to me when I look at such code. I mean
many pages long functions full of GOs, two letter variables
and such (and zero comments). I cannot
believe that humans can write this code. I always
think the author was some ugly 'Terminator' from the future,
though lately the Terminators seem to be blond and good looking.

>
> --tim (who has used the FORMAT string mentioned in
> http://www.tfeb.org/lisp/obscurities.html in anger)
From: John Thingstad on
On Wed, 28 Feb 2007 04:30:06 +0100, <job-271842874(a)craigslist.org> wrote:

> Ken Tilton wrote:
>> Paul Wallich wrote:
>>> job-271842874(a)craigslist.org wrote:
>>>
>>>> A friend passed on an article regarding the difficulty job candidates
>>>> had in producing even simple programs (simple as in should take a
>>>> minute or less). One example was a program to print the numbers 1 to
>>>> 100 except that "Fizz" should be substituted for numbers divisible by
>>>> 3, "Buzz" should be substituted for numbers divisible by 5, and
>>>> "FizzBuzz" should be substituted for numbers divisible by both 3 and
>>>> 5.
>>>>
>>> I'd probably brute-force the problem with a simple cond with a nested
>>> conditions, along the lines of
>>> (cond ((zerop (mod i 5))
>>> (cond ((zerop (mod i 3)) (print "FizzBuzz"))
>>> (t (print "Buzz"))))
>>> ((zerop (mod i 3))
>>> (print "Fizz"))
>>> (t (print i)))
>> I would object to using cond to implement if, and the redundant code
>> testing for (mod i 3) and associating it with Fizz.
>
> I agree. I expect mod is fast, but I don't like to repeat myself.
>

rem is fast.. mod conses on fractions on the heap

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
From: Pillsy on
On Feb 27, 11:14 pm, GP lisper <spamb...(a)CloudDancer.com> wrote:
[...]
> Loop is a Domain Specific Language, something that many loop haters
> overlook, as they will also cheer DSLs as a Lisp strength.

Oh, I know it's a DSL. I just think it's a crappy DSL. ITERATE is the
same sort of DSL, but is much better---easier for editors to indent
right, Lispy looking, and straightforward to extend with macros.

Cheers,
Pillsy

From: Thierry Pirot on
job-271842874writes:
> Thierry Pirot wrote:

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

> Maybe I'm reading this incorrectly, but wouldn't that always print i?
>
Let's run
CL-USER> (printing 3)
Fizz
NIL
CL-USER> (printing 4)
4
NIL
CL-USER> (printing 5)
Buzz
NIL
CL-USER> (printing 30)
FizzBuzz
NIL

Let's read
http://www.lispworks.com/documentation/HyperSpec/Body/m_cond.htm
cond, a root of Lisp, is not a function,
it sequentially evaluates its clauses' antecedent until one is true and then
returns the evaluation of the consequent.
t in the last clause can be thought of as an "otherwise".
--
Take it Easy Don't worry Be Happy

Thierry

�������o�o��������o�o��������o�o��������o�o��������o�o�������