Closed nick8325 closed 5 years ago
This was a nice puzzle. It results from the system trying to pull in or report possibly undefined predicates. The clause q(Pred) :- call(Pred).
causes it to derive that q/1 is a meta predicate. This implies it wants to see what is being called from the q([])
call, but []
is not considered a callable term in SWI-Prolog.
As there is a clause q([])
this looks like an ok program, but after deriving the meta-predicate, q/1 is always called with a qualified (Module:Callable) term and the first clause thus never fires and calling p
will indeed result in a type error.
Bottom story: it is arguable that this error is produced and the program is flawed.
Ah! Thanks for the explanation, that's all very clear now. I'd forgotten that modules interact with meta-predicates - I can see that q/1 isn't going to work inside a module. Feel free to close the bug report.
(I was originally hoping to define a meta-predicate that takes either a predicate or a list of predicates as an argument, hence the rather odd test case. I suppose that may be doable using module_transparent
, but I think it's better for me to change my design instead.)
Yes, lists of goals is not really a good idea. It can be done, but simply using a conjunction (A,B) if typically better design.
Here is my file,
funny.pl
:The file can be consulted, and indeed
p
executes correctly:However, running the compiler gives an error:
This is using version 8.0.2.