[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [NOISE] Curly braces [was Re: Curl]




Would it be difficult to write a "matheval" macro in Scheme
or Lisp that evaluates arithmetic expressions in infix notation
so one could write

(define (roots a b c)
  (let ((d (matheval b ^ 2 - 4 * a * c < 0))
   (if (< d 0) 'none
     (list
        (matheval (- b + sqrt d) / (2 * a))
        (matheval (- b - sqrt d) / (2 * a))


I don't have time right now, but this looks like a
2 hour project using Olin Shiver's approach.

Since I don't use hygenic macros myself, I'm not
sure if this kind of translation is easy to do or not.
Using "dangerous macros" (that can arbitrarily rearrange
and evaluate their arguments at runtime) this is
easy to do.

---Tim Hickey---


On Fri, 30 Nov 2001, Christopher Barber wrote:

> > Infix almost always makes it easier to transcribe a math formula into a
> > computer program, but relative ease of readability/debugging/
> > understanding is debatable. IMO.
>
> No one is taught math using prefix notation, so forcing them to learn it is
> a barrier to usability.  I suppose it is possible that given enough
> experience with its use, you might become proficient enough to grok it as
> easily as infix, but why force humans to do what computers can do easily?
>
> I also would not underestimate the importance of having formulas look the
> same as they do in a book.  Not only does it lower transcription errors, it
> also makes it easier for people reading the code to verify that the correct
> formula is being used.
>
> - Christopher
>