Re: Disjunction in phrase/[2,3]

Wouter Beek <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <CAE1un7PDL7_zcHA9j2ACCO4MWWss=b2exfWBqcLGijuVJGaTwA@mail.gmail.com>
Hi Jan,

Thanks for the quick reply! Your solution indeed works for DCGs with no
extra arguments (only the difference list parameters), as was applicable to
the example I gave. But could one also achieve this result for DCGs with
extra arguments?

I'll give an example:
~~~{.pl}
a(C) -->
  x((b ; c), C).
b(98) --> [98].
c(99) --> [99].

:- meta_predicate(x(//,?,?,?)).
:- meta_predicate(x(3,?,?,?)).
x(M:DCG1, C, A, B):-
  atom(DCG1), !,
  DCG2 =.. [DCG1,C],
  phrase(M:DCG2, A, B).
x(M:DCG1, C, A, B):-
  DCG1 =.. [;|Ps],
  member(P, Ps),
  DCG2 =.. [P,C],
  phrase(M:DCG2, A, B).
~~~

I have tried to comment out either of the meta_predicate/1 directives in
the above example.
- Without the //-variant swipl warns for the use of  disjunction (as
explained in your email, this behavior is expected).
- Without the 3-variant swipl warns for the missing predicates b/2 and c/2
(which is also understandable, since the // does not indicate the number of
arguments the DCG rule has).
Is there a way of combining both directives?

---
Cheers!,
Wouter.

E-mail: [email protected]
WWW: www.wouterbeek.com
Tel.: 0647674624


On Sun, Jul 28, 2013 at 11:03 AM, Jan Wielemaker <[email protected]> wrote:

> On 07/28/2013 10:29 AM, Wouter Beek wrote:
> > Hi all,
> >
> > I get the following warning for the use of disjunction in meta-DCG rules:
> > ~~~
> > Warning: The predicates below are not defined. If these are defined
> > Warning: at runtime using assert/1, use :- dynamic Name/Arity.
> > Warning:
> > Warning: test:;/4, which is referenced by
> > Warning:        c:/prolog/webqr/test.pl:6:5: 1-st clause of test:a/2
> > ~~~
> >
> > Am I doing something wrong or is the missing predicates check too
> > restrictive?
> >
> > Sample code:
> > ~~~{.pl}
> > a -->  x((b ; c)).
> > b --> [98].
> > c --> [99].
> > :- meta_predicate(x(2,?,?)).
>
> Works with this declaration.  DCG bodies are are bit more complicated
> than just '2', so you must tell the system.
>
> :- meta_predicate(x(//,?,?)).
>
>         Cheers --- Jan
>
> > x(DCG, A, B):- phrase(DCG, A, B).
> > ~~~
> >
> > ---
> > Cheers,
> > Wouter Beek.
> >
> > E-mail: [email protected]
> > WWW: www.wouterbeek.com
> > Tel.: 0647674624
> > -------------- next part --------------
> > HTML attachment scrubbed and removed
> > _______________________________________________
> > SWI-Prolog mailing list
> > [email protected]
> > https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
> >
>
>
-------------- next part --------------
HTML attachment scrubbed and removed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.