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

infix notation [Re: Macros and little languages]



Dave Long wrote:

> EWD1300:
> > A little hesitance was induced when my late colleague Wouter Peremans
> > remarked in passing that infix notation was of course "a notational
> > relic".  It made me realize why I like it so much for associative
> > operators: it allows us to write p+q+r without being forced to choose
> > between (p+q)+r and p+(q+r); in prefix notation, the choice between
> > ++pqr and +p+qr would have been unavoidable.

As a notation,

  (+ p q r)

does not a priori choose between

  (+ p (+ q r))

and

  (+ (+ p q) r)

[This argument doesn't scale to expressions like x+y*z, but there I've 
 always viewed the unambiguity of prefix to be an advantage,
 especially in the classroom.]

> > [EWD249: Programming (or problem solving in general?) as the judicious
> > postponement of decisions and commitments]
> >
> > The main reason to stick to the infix notation for the usual
> > operators was, of course, that we all are so terribly used to it,
> > but the associativity does play an honest role: I did introduce --
> > with great satisfaction! -- infix operators for what I used to denote
> > by max(x,y) and gcd(x,y), and find that I don't introduce anymore
> > infix operators that are not associative.

In PLT Scheme,

  > (1 . max . 2)
  2
  > (1 . max . (3 . * . 4))
  12

Shriram