A strange error while using qcompile/1

I am having a strange experience while using builtin qcompile/1
receiving, for instance,

ERROR:    catch/3: Undefined procedure: ejockey:module/2
Warning: Redefined static procedure zdd:begin_of_file/0

To explain trouble, error messages, and logs of five queries 1-5 are listed below.

As I thought I must be missing some simple thing as is often, I have skimmed the source code of qcompile/1 but got any sympton.

ERROR messages.

% ?-  zdd:qcompile(misc(zdd)), zdd:qcompile(misc('emacs-jockey')).
%@ ERROR: /Users/cantor/devel/zdd/prolog/misc/prolog-elisp.pl:1:
%@ ERROR:    '$c_call_prolog'/0: Undefined procedure: zdd:module/2
%@ ERROR:      However, there are definitions for:
%@ ERROR:            module/1

% ?-  zdd:qcompile(misc(zdd)), zdd:qcompile(misc('prolog-elisp')).
%@ Warning: /Users/cantor/devel/zdd/prolog/misc/prolog-elisp.pl:0:
%@ Warning:    Redefined static procedure zdd:begin_of_file/0
%@ ERROR: /Users/cantor/devel/zdd/prolog/misc/prolog-elisp.pl:1:
%@ ERROR:    catch/3: Undefined procedure: zdd:module/2
%@ ERROR:      However, there are definitions for:
%@ ERROR:            module/1

Five tries using qcompile/1.

Try 1. (error)

% ?-  qcompile(misc(zdd)), qcompile(misc('emacs-jockey')).
%@ true.
% ?-  qcompile(misc(zdd)), qcompile(misc('emacs-jockey')).
%@ ERROR: /Users/cantor/devel/zdd/prolog/misc/zdd.pl:1:
%@ ERROR:    catch/3: Undefined procedure: ejockey:module/2
%@ ERROR:      However, there are definitions for:
%@ ERROR:            ejockey:module/1
%@ ERROR:            module/1
%@ ERROR:            module/1
%@ Warning: /Users/cantor/devel/zdd/prolog/misc/zdd.pl:1:
%@ Warning:    Goal (directive) failed: ejockey:module(zdd,[sat/1,family_of_sets/2])
%@ Warning: /Users/cantor/devel/zdd/prolog/misc/zdd.pl:20:
%@ Warning:    Redefined static procedure ejockey:term_expansion/2
%@ Warning:    Previously defined at /Users/cantor/devel/zdd/prolog/misc/emacs-jockey.pl:18
%@ Warning: /Users/cantor/devel/zdd/prolog/misc/zdd.pl:734:
%@ Warning:    Local definition of ejockey:family_of_sets/2 overrides weak import from zdd
%@ Warning: /Users/cantor/devel/zdd/prolog/misc/zdd.pl:5132:
%@ Warning:    Local definition of ejockey:sat/1 overrides weak import from zdd
%@ true.

Try 2. (success)

% ?-  user:qcompile(misc(zdd)), user:qcompile(misc('emacs-jockey')).
%@ true.
% ?-  user:qcompile(misc(zdd)), user:qcompile(misc('emacs-jockey')).
%@ true.

Try 3. (success)

% ?-  system:qcompile(misc(zdd)), system:qcompile(misc('emacs-jockey')).
%@ true.
% ?-  system:qcompile(misc(zdd)), system:qcompile(misc('emacs-jockey')).
%@ true.

Try 4. (success)

% ?-  pac:qcompile(misc(zdd)), pac:qcompile(misc('emacs-jockey')).
%@ true.
% ?-  pac:qcompile(misc(zdd)), pac:qcompile(misc('emacs-jockey')).
%@ true.

Try 5. (error)

% ?-  ejockey:qcompile(misc(zdd)), pac:qcompile(misc('emacs-jockey')).

%@ ERROR: /Users/cantor/devel/zdd/prolog/misc/zdd.pl:1:
%@ ERROR:    catch/3: Undefined procedure: ejockey:module/2
%@ ERROR:      However, there are definitions for:
%@ ERROR:            module/1
%@ Warning: /Users/cantor/devel/zdd/prolog/misc/zdd.pl:1:
%@ Warning:    Goal (directive) failed: ejockey:module(zdd,[sat/1,family_of_sets/2])
%@ Warning: /Users/cantor/devel/zdd/prolog/misc/zdd.pl:20:
%@ Warning:    Redefined static procedure ejockey:term_expansion/2
%@ Warning:    Previously defined at /Users/cantor/devel/zdd/prolog/misc/emacs-jockey.pl:18
%@ Warning: /Users/cantor/devel/zdd/prolog/misc/zdd.pl:734:
%@ Warning:    Local definition of ejockey:family_of_sets/2 overrides weak import from zdd
%@ Warning: /Users/cantor/devel/zdd/prolog/misc/zdd.pl:5132:
%@ Warning:    Local definition of ejockey:sat/1 overrides weak import from zdd
%@ true.

% ?-  ejockey:qcompile(misc(zdd)), pac:qcompile(misc('emacs-jockey')).
%@ true.

Any hint is appreciated.

Kuniaki Mukai

Hard to tell. The fact that module/2 is considered undefined probably means that goal/term expansion somehow creates terms before the module declaration and causes the module declaration to be interpreted as a normal directive. The messages about begin_of_file also hint a that. This dummy term is inserted in the expansion chain to allow expansion to act on the entire file scope. It is used in the XSB emulation to generate the module header on the fly.

In itself, a goal like module:qcompile(file) sounds weird. Try turning it into a small example you can share and explain.

Thanks for response.

Before posting, I had tried to simplify to reproduce that errors, but to fail.

Current workaround is to assert the following clause at an appropriate place:


user:non_meta_qcompile(X):- qcompile(X).

I am now “gtracing”, which I am not familiar but wish to be able to use for it for debugging for larger codes.

Kuniaki Mukai

Hi Jan,

Adding ‘begin_of_file’ atom to the list

  • variables ,

  • directives , and

  • ‘end_of_file’ atom ,

for which my term_expansion must fail in order

to pass them to possible other ones.

Fortunately, this workaround works as far as quick testing.

I was not aware of the begin_of_file, untill you metioned.

Begin-end structure always sounds useful because of symmetricity.

Thank you for help.

Kuniaki Mukai

I have simplified the trouble case so that it could be reproduced easily.

My term_expansion treated the atom begin_of_file as an atomic unit clause, and

then put a module prefix to the clause. This seems the cause of the trouble.

Although I am not sure on this, anyway I should be careful of “begin_of_file” as

well as “end_of_file” in writing term_expansion.


% cat a.pl

:- module(a, []).

term_expansion(begin_of_file, a:begin_of_file).

% cat b.pl

:- module(b, []).

% swipl

Welcome to SWI-Prolog (threaded, 64 bits, version 8.1.5-8-gcc5023a8c-DIRTY)

?- qcompile(a), qcompile(b), module(a).

true.


ERROR: /Users/cantor/devel/zdd/prolog/misc/b.pl:1:

ERROR:    catch/3: Undefined procedure: a:module/2

ERROR:      However, there are definitions for:

ERROR:            module/1

ERROR:            module/1

Warning: /Users/cantor/devel/zdd/prolog/misc/b.pl:1:

Warning:    Goal (directive) failed: a:module(b,[])

true.

Kuniaki Mukai