LWN.net Logo

It's a mistake to ignore the customer

It's a mistake to ignore the customer

Posted Dec 6, 2012 18:27 UTC (Thu) by vonbrand (subscriber, #4458)
In reply to: It's a mistake to ignore the customer by etienne
Parent article: GNU Guile 2.0.7 released

"Precedence" is a red herring: The precedence of +-*/ is fixed, you can easily place "all others" in one (or two) categories). Yes, C went overboard with its 13 levels; APL went overboard the other way (all operators left associative with the same precedence).

Come on, parsing infix (precedence and all) is ridiculously easy. A nice, top-down parser for C is described in Fraser and Hanson's book on LCC.


(Log in to post comments)

It's a mistake to ignore the customer

Posted Dec 7, 2012 7:23 UTC (Fri) by mathstuf (subscriber, #69389) [Link]

I like Haskell's solution: custom defined operators with 10 available precedence levels (I forget exactly, but I remember 10) with the "standard" ones spaced out along it.

It's a mistake to ignore the customer

Posted Dec 7, 2012 9:39 UTC (Fri) by ekj (guest, #1524) [Link]

Isn't that terribly hard to read ?

How do you know what will happen with:

a + b [custom] c * d

Means:

(a+b) [custom] (c * d)

Or:

((a+b) [custom] c) * d

Or:

a + (b [custom] c) * d

It's a mistake to ignore the customer

Posted Dec 7, 2012 16:18 UTC (Fri) by mathstuf (subscriber, #69389) [Link]

Generally, the operators don't work just on numbers and so they don't mix much with the common ones much. Its to establish order within a class of operators (e.g., within the monad operators, arrow operators, and so on). If mathematical expressions tend to get passed in to them, make them lower precedence, otherwise you can play with the higher ones.

It's a mistake to ignore the customer

Posted Dec 7, 2012 10:12 UTC (Fri) by etienne (subscriber, #25256) [Link]

> Come on, parsing infix (precedence and all) is ridiculously easy.

It is not the parsing which is a problem, it is the description of functions.
In pre/post-fix notation, each operator is a function, so you have those functions - thinking in C:
number + ( number, number, ...);
number * ( number, number, ...);
boolean = ( number, number, ...);
boolean < ( number, number, ...);
boolean && ( boolean, boolean, ...);
There is nothing special at all about these functions, compared to any other functions like
boolean print ( ... );

I do not see how you can define a single and simple function type when you use infix, so that in a complex class tree you can derive a class and replace a random function with a simple "addition" or "greater_than". Maybe define a priority for each and every functions? Can this priority change at run-time? at instantiation time?

Note that I am using infix for my programming, so I deal with it...
Note also that I do not want to teach infix to someone writing from right to left, nor do I want to translate mathematics text into these kind of languages...

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds