[mercury-users] Difference of Predicate Declaration from Implementation
Mark Brown
mark at csse.unimelb.edu.au
Tue Sep 4 20:21:00 AEST 2007
On 04-Sep-2007, Stormie Stormie <stormie at hotmail.it> wrote:
>
>
> I have question from calculator.m example in mercury
>
> 1) Arguments in the predicate declaration (e.g. fullexpr) are different from its implementation.
> e.g. arguments for fullexpr are three, but it just takes one (i.e. X) in its implementation.
> Why is that so?
The clauses are DCG-rules, rather than ordinary rules. See section 2.11
of the reference manual.
>
> 2) What is the purpose of ['\n']
That is a DCG-goal, which is described in section 2.12.
(Note that state variables provide a similar benefit to DCGs, but are
more flexible, and are thus usually preferred.)
> -------------------------------------------------------------
>
> % Simple recursive-descent parser.
>
> :- pred fullexpr(expr::out, list(char)::in, list(char)::out) is semidet.
>
> fullexpr(X) -->
> expr(X),
> ['\n'].
For example, this DCG-rule is equivalent to:
fullexpr(X, V0, V) :-
expr(X, V0, V1),
V1 = ['\n' | V].
Hope that helps.
Cheers,
Mark.
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to: mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions: mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the users
mailing list