[mercury-users] Pred defns
Lee Naish
lee at cs.mu.OZ.AU
Tue Apr 7 13:14:24 AEST 1998
In message <19980407020404.54120 at mundook.cs.mu.OZ.AU>Fergus wrote:
>However, DCGs *can* be interpreted as just statements in logic,
>so long as you use `phrase/3' (currently we *don't*, which is
>probably something that we should fix) to invoke them from non-DCG code.
This is a bit misleading. Essentially all predicates defined using DCGs
(and you better define *all* clauses using DCG notation - no ordinary
clauses mixed with DGC clauses in one predicate definition) are lumped
together into one predicate ('-->'/2) which is essentially inpterpreted
by phrase. The arguments of the ('-->'/2) predicate are treated more
like data than code.
In exactly the same sense we can say the following:
However, C++ *can* be interpreted as just statements in logic,
so long as you use `interpret_C_plus_plus/3'. Of course there is a
small practical difference: *no-one* will understand the definition of
`interpret_C_plus_plus/3' whereas a couple of people (perhaps several)
will understand the definition of `phrase/3'.
I think the syntactic transformation is the best way to
explain DCGs and its simple enough to not cloud the logic. There are
other aspects of Mercury you are not likely to find in a logic text book
also. Look at the (implict) quantification in conditionals - a logician
would be horrified (and yet its exactly what we want as logic
*programmers*). Compromises at the syntactic level are fine, as long as
they don't cloud the declarative meaning too much (and ideally they
should clarify all readings by reducing unnecessary detail, such as
explicit quantifiers, duplicated code, extra arguments etc).
lee
More information about the users
mailing list