[mercury-users] Re: Fergus' hack

Peter Schachte pets at students.cs.mu.oz.au
Mon Oct 13 17:50:45 AEST 1997


On Mon, 13 Oct 1997, Bart Demoen wrote:

> Can anyone show me an example where one saves considerable code
> duplication with the extra argument while this is not possible with
> the "two different predicates" approach ?

Depends on what you mean by "show."

I once worked on a Prolog project that had a GUI which showed a mathematical
expression which the user could edit.  I had a single DCG which (barely) 
worked both as a parser and generator, by careful use of cuts and careful
ordering.  If I'd had to write and maintain two whole grammars, one for
parsing and one for generating, there would have been a lot of code
duplication.  The hack of using cuts was never very satisfactory, but it
never occurred to me to have an extra argument to indicate whether I wanted
the "loose" (parsing) or "canonical" (generating) version of the grammar.  I
think that would have worked better (though the extra argument would have
been annoying; this would be a perfect application for "global variables").


-Peter Schachte			| A clean environment is a human right like 
pets at cs.mu.OZ.AU		| any other --The Dalai Lama, 1990
http://www.cs.mu.oz.au/~pets/	|
PGP key available on request	|




More information about the users mailing list