<br><div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>> Off topic: I am reading Paul Graham's ANSI Common Lisp and I have a<br>
> little question: why does he uses a lot (at least until chapter 4)<br>> "and" clauses when I think he should use the "when" macro? For<br>> example, in this code snip from figure 4.1:<br>>
<br>> ;; This is a binary search algorithm as you may guess.<br>> (defun bin-search (obj vec)<br>> (let ((len (length vec)))<br>> (and (not (zerop len)) ;Here is the and clause that I may change for<br>> ;a when
<br>> (finder obj vec 0 (- len 1)))))<br>><br>> (defun finder (obj vec start end)<br>> ...)<br>><br>> I've read that at least three times I think and it seems that there<br>> will be more.
<br>> I know that the and clause gives the desired behavior of returning<br>> the last value that satisfies it or the first one that doesn't, but<br>> I would have used a when for some of the cases I've read (it is more
<br>> readable for me, I think).<br>> Is he using the and clause for some reason that eludes me or is it<br>> just a personal taste?<br><br>In many cases I think it's just personal taste, i.e., a style issue<br>
like the one I mentioned above.<br><br>But maybe not. If you consider the published code as a snapshot of a<br>real application, some method to this madness emerges (maybe). In<br>particular, consider the code over time. Perhaps he started out with
<br><br> (and (not (zerop len))<br> (other code)<br> (finder obj vec 0 (- len 1)))<br><br>and then deleted the second clause. Maybe he didn't want to change<br>it. Maybe he thought he might, at some later date, have to add some
<br>more code in the middle. Once you shift back and forth between<br><br> (when (foo)<br> (baz))<br><br>and<br><br> (when (and (foo) (bar))<br> (baz))<br><br>enough times, you start to want to skip the middle man and just go for
<br><br> (and (foo)<br> (baz))<br><br>every time, in case you have to add the middle (bar) later.<br><br>Or so it seems to me, anyway. :)<br><br>I haven't really thought about it all that much, but I might use the
<br>following rule of thumb: Start out with<br><br> (when (foo)<br> (baz))<br><br>The first time you have to change it to<br><br> (when (and (foo) (bar))<br> (baz))<br><br>change it to<br><br> (and (foo)<br> (bar)
<br> (baz))<br><br>instead and leave it that way forever after. If it has changed once,<br>it'll probably change again. :)<br><br>-- Larry<br><br>_______________________________________________<br>quiz mailing list
<br><a href="mailto:quiz@common-lisp.net">quiz@common-lisp.net</a><br><a href="http://common-lisp.net/cgi-bin/mailman/listinfo/quiz">http://common-lisp.net/cgi-bin/mailman/listinfo/quiz</a><br></blockquote></div><br>Outstanding. Thanks for the answer, Larry. I was starting to think that was the answer, but you stated it very clear.
<br>