The usual behavior of Prolog compilers is to rewrite ..., X, ... as ..., call(X), ... For example:
Code: Select all
GNU Prolog 1.4.0
By Daniel Diaz
Copyright (C) 1999-2010 Daniel Diaz
| ?- assertz((a(X) :- X)).
| ?- listing.
% library(swi_hooks) compiled into pce_swi_hooks 0.00 sec, 3,928 bytes
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 5.11.13)
Copyright (c) 1990-2011 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).
?- assertz((a(X) :- X)).
:- dynamic a/1.
The Logtalk compiler does the same (note that the predicate clause returned by expand_term/2 in your example is only the expansion of the grammar rule, not the final, compiled, predicate clause generated by the compiler). One reason to avoid using meta-variables (not wrapped in a call/1 control construct) is to avoid some semantic and portability pitfalls when cuts are present. Consider:
a(X) :- X.
b(X) :- call(X):
Calling both predicates with a cut as argument results in one solution for a/1 but two solutions for b/1 (as the call/1 control construct is opaque to cuts). Regarding portability issues, not all Prolog compilers behave as illustrated for GNU Prolog or SWI-Prolog above. For example:
Code: Select all
ECLiPSe Constraint Logic Programming System [kernel]
Kernel and basic libraries copyright Cisco Systems, Inc.
and subject to the Cisco-style Mozilla Public Licence 1.1
(see legal/cmpl.txt or www.eclipse-clp.org/licence)
Source available at www.sourceforge.org/projects/eclipse-clp
GMP library copyright Free Software Foundation, see legal/lgpl.txt
For other libraries see their individual copyright notices
Version 6.1unstable #46 (i386_macosx), Tue Oct 12 02:32 2010
[eclipse 42]: assertz((a(X) :- X)).
X = X
Yes (0.00s cpu)
[eclipse 43]: listing.
Yes (0.01s cpu)
Thus, detecting and warning the user for variables used as meta-calls is a desirable feature but not as trivial (to implement) as it may seem. It's, however, in my TODO list.
P.S. The fix for the bug you reported is already committed.