Re: DCG meta-predicate error

Paulo Moura <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
Hi Samer,

On 18/03/2014, at 18:11, Samer Abdallah <[email protected]> wrote:

> Hi,
> There appears to be a bug in the handling of meta-predicates that
> expect a DCG goal as an argument:
> 
> :- meta_predicate foo(//,?,?).
> 
> foo(G) --> phrase(G).
> 
> test --> foo({writeln(hello)}).
> 
> Using SWI v. 7.1.7 results in 
> Warning: The predicates below are not defined. If these are defined
> Warning: at runtime using assert/1, use :- dynamic Name/Arity.
> Warning: 
> Warning: {}/3, which is referenced by
> Warning:        /Users/samer/src/sandpit/prolog/test.pl:4: 1-st clause of test/2

I get:

$ swipl
% /Users/pmoura/.plrc compiled 0.00 sec, 2 clauses
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.1.9-53-g30fa74b-DIRTY)
Copyright (c) 1990-2014 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

?- [user].
:- meta_predicate foo(//,?,?).
|: 
|: foo(G) --> phrase(G).
|: 
|: test --> foo({writeln(hello)}).
|: % user://1 compiled 0.00 sec, 6 clauses
true.

?- listing(test/2).
test(A, B) :-
	foo({writeln(hello)}, A, B).

true.

?- listing(foo/3).
:- meta_predicate foo(//,?,?).

foo(A, B, C) :-
	phrase(A, B, C).

true.

?- phrase(test, []).
hello
true.

If I put your code in a file and consult it I get no warnings:

$ swipl
% /Users/pmoura/.plrc compiled 0.00 sec, 2 clauses
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.1.9-53-g30fa74b-DIRTY)
Copyright (c) 1990-2014 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

?- [samer].
% samer compiled 0.00 sec, 6 clauses
true.

Are you using a different SWI-Prolgo version or testing the code in a different way?

Cheers,

Paulo

-----------------------------------------------------------------
Paulo Moura
Logtalk developer

Email: <mailto:[email protected]>
Web:   <http://logtalk.org/>
-----------------------------------------------------------------
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.