# A strange error while using qcompile/1

**URL:** <https://swi-prolog.discourse.group/t/a-strange-error-while-using-qcompile-1/590>\
**Category:** Help!\
**Created:** [April 27, 2019, 5:10am UTC](https://swi-prolog.discourse.group/t/a-strange-error-while-using-qcompile-1/590 "2019-04-27T05:10:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kuniaki.mukai](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@kuniaki.mukai](https://swi-prolog.discourse.group/u/kuniaki.mukai)\
**Post date:** [April 27, 2019, 5:10am UTC](https://swi-prolog.discourse.group/t/a-strange-error-while-using-qcompile-1/590/1 "2019-04-27T05:10:25Z")

</div>

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

```prolog
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.

```prolog
% ?- 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)

```prolog
% ?- 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)

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

```

### Try 3. (success)

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

```

### Try 4. (success)

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

```

### Try 5. (error)

```prolog
% ?- 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

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [April 27, 2019, 9:59am UTC](https://swi-prolog.discourse.group/t/a-strange-error-while-using-qcompile-1/590/2 "2019-04-27T09:59:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kuniaki.mukai](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@kuniaki.mukai](https://swi-prolog.discourse.group/u/kuniaki.mukai)\
**Post date:** [April 27, 2019, 10:52am UTC](https://swi-prolog.discourse.group/t/a-strange-error-while-using-qcompile-1/590/3 "2019-04-27T10:52:00Z")

</div>

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:

```prolog

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

---

<div class="post-metadata">

**Author:** ![kuniaki.mukai](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@kuniaki.mukai](https://swi-prolog.discourse.group/u/kuniaki.mukai)\
**Post date:** [April 27, 2019, 6:20pm UTC](https://swi-prolog.discourse.group/t/a-strange-error-while-using-qcompile-1/590/4 "2019-04-27T18:20:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kuniaki.mukai](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@kuniaki.mukai](https://swi-prolog.discourse.group/u/kuniaki.mukai)\
**Post date:** [April 28, 2019, 10:15am UTC](https://swi-prolog.discourse.group/t/a-strange-error-while-using-qcompile-1/590/5 "2019-04-28T10:15:48Z")

</div>

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.

```prolog

% 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
