Subject: Re: "Choose the Right Language" in "Tutorial" by Norvig and Pitman
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 30 Apr 2002 03:04:25 GMT
Newsgroups: comp.lang.lisp
Message-ID: <aal1jp$un6ll$1@fido.engr.sgi.com>
Bruce Hoult  <bruce@hoult.org> wrote:
+---------------
| rpw3@rigden.engr.sgi.com (Rob Warnock) wrote:
| > Marc Battyani <Marc.Battyani@fractalconcept.com> wrote:
| > +---------------
| > | So be happy. They already have done it! It's called XEXPR
| > | Look at http://www.w3.org/TR/xexpr/
| > ...
| > | <define name="factorial" args="x">
| > |  <if>
| > |    <lt><x/>2</lt>
| > |    <x/>
| > |    <multiply>
| > |      <x/>
| > |      <factorial><subtract><x/>1</subtract></factorial>
| > |    </multiply>
| > |  </if>
| > | </define>
| > | 
| > | Brilliant no ?
| > +---------------
| > 
| > No. They were so intent on showing how clever they were with the syntax
| > that they got the definition of this simple function *wrong*!! ;-}  ;-}
| > 
| > [Hint: The consequent should be a certain numeric constant, not "<x/>".]
| 
| No, it's fine.  In fact, they could have increased the 2 to 3 (or 
| changed the lt to le).
+---------------

Uh... I don't *think* so!  Isn't "0!" *defined* to be "1"?!?
The above code incorrectly calculates 0! --> 0.

Note that the interative version (using an internal define) given
further down the referenced page gets it right, using "1" as the
base case for the value of "<product/>".


-Rob

-----
Rob Warnock, 30-3-510		<rpw3@sgi.com>
SGI Network Engineering		<http://reality.sgiweb.org/rpw3/>
1600 Amphitheatre Pkwy.		Phone: 650-933-1673
Mountain View, CA  94043	PP-ASEL-IA

[Note: aaanalyst@sgi.com and zedwatch@sgi.com aren't for humans ]