[m-dev.] Infix syntax proposal

Douglas Michael Auclair dauclair at hotmail.com
Wed Aug 14 21:43:24 AEST 2002

Dear all,

I propose the following amendment to the infix syntax -- add a declaration 
to the language of the form:

:- infix foo, bar, baz.

This declaration allows the above binary functions (foo, bar, and baz) to be 
used in the following way (e.g.):

X foo Y, 3 bar 7, "Quux" baz 42.

It transforms the above into:

X `foo` Y, 3 `bar` 7, "Quuz" `baz` 42.


Working a good deal with the pprint module has made Doc1 `<>` Doc2 both 
tedious and alien.  I also define quite a few binary functions and would 
like them to be on equal footing with the builtins at the source level when 
I plan to use them as infix functions.


I have attached a toy program that transforms files with infix declarations 
(let's call the file foo.infix) to .m files.  It is used thus:

./infix < foo.infix > foo.m

I propose that this infix transformer, if accepted, become part of the 
(m)make process, so that the first source transformation resolves infix 
calls and is transparent to users of mmake/mmc.


1. Very little to compilation time: running infix over large programs is not 
noticeable.  There is one more IR that must be passed around either in 
memory or as a (temporary) file.
2. No syntactic/semantic _cost_:  old modules compile as before, and, even 
with an infix declaration, one may still use the back-quote convention or 
the prefix style -- a smart infix pass will not disturb these pre-existing 
constructs (even the attached "toy" program works well with these 
3. New-style infix modules will not compile under the old system without 
first being transformed.
4. Increased opportunities for compile-time errors:  the user must remember 
to declare target binary functions as infix, otherwise the compiler will 
report an error at or near the infix call.


1. User-defined and declared infix calls are treated as equals to builtin 
binary functions at the source level.


I have used this proposed infix syntax and the transforming program on two 
projects so far.  The new syntax seems more natural to use and to review 
than the back-quote convention.

Douglas Auclair

Chat with friends online, try MSN Messenger: http://messenger.msn.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: infix.tgz
Type: application/x-gzip-compressed
Size: 1547 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/developers/attachments/20020814/0304c55a/attachment.bin>

More information about the developers mailing list