[m-dev.] op/3 syntax and semantics

doug.auclair at logicaltypes.com doug.auclair at logicaltypes.com
Thu Feb 2 08:35:40 AEDT 2006


Dear all,

Fergus asked for a semantic and syntactic definition of the op/3 declaration.  Since it is implemented the same way in Mercury as it is in Prolog (except the extent of the effect: in Mercury I've limitted its extent to the module in which it is declared.  Prolog's op/3 has universal extent (I consider this to be a misfeature, but this cannot be helped: the Prolog module system was an afterthought, added long after op/3, so there is a corpus of Prolog code that depend on this misfeature.  Ugh!)).  Since Mercury's op/3 and Prolog op/3 are (nearly) equivalent, here is a useful specification, lifted from http://gollem.science.uva.nl/SWI-Prolog/Manual/operators.html#op/3:

-----
op(+Precedence, +Type, :Name)
Declare Name to be an operator of type Type with precedence Precedence. [deleted Name as list] Precedence is an integer between 0 and 1200. [deleted Precedence 0 deleting op] Type is one of: xf, yf, xfx, xfy, yfx, yfy, fy or fx. The `f' indicates the position of the functor, while x and y indicate the position of the arguments. `y' should be interpreted as ``on this position a term with precedence lower or equal to the precedence of the functor should occur''. For `x' the precedence of the argument must be strictly lower. The precedence of a term is 0, unless its principal functor is an operator, in which case the precedence is the precedence of this operator. A term enclosed in brackets ( ... ) has precedence 0.
-----

The minor additional correction is that Mercury defines more specifications that what Prolog allows -- Prolog's allowable specifications are: xf, yf, xfx, xfy, yfx, yfy, fy or fx (actually, 'yfy' is an SWI addition, other Prologs do not support this); Mercury's (as per module ops): fx ; fy ; xf ; yf ; xfx ; yfx ; xfy ; fxx ; fxy ; fyx.

Helpful?  Coming from a Prolog programming background, I mistakenly assumed op/3 was part of the lexicon here (especially after seeing the several aborted attempts at its implementation as part of the compiler).  I suppose some documentation for the Mercury user's manual is required.  Does the above suffice?

Sincerely,
Doug Auclair

P.S. I will send the 'diff -u' for the affected modules as soon as I have access to the source (after work)

--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list