8.x user:term_expansion -- module handling -- autoload complex issue

I have only recently downloaded 8.x (8.2.1 actually)… beforehead I used 7.x

My code (clog.pl) defines user:term_expansion and goal_expansion, and sets also predicate properties for the expanded predicates by @/2… (it is Contralog, a forward chaining extension to Prolog)

Then I am relying very heavily on the expanded code and DCG together (enParser/enGen it creates a parser from DCG that works data-driven way, similar to CYK)

What I get is, already when consulting the stuff… as if the module mechanism/autoload mechanism didn’t work correctly

ERROR:    Domain error: `module_file' expected, found `'c:/program files/swipl/library/apply.pl''

ERROR:    '$eval_if'/1: Unknown procedure: clog:switchOut/0
ERROR:      However, there are definitions for:
ERROR:            enGen:switchOut/0
ERROR:            enParser:switchOut/0

ERROR:    plunit:expand_test/4: Unknown procedure: plunit:maplist/3

And as a final point, if I call ‘edit’ to check what is with the code, I get hundreds of errors - mostly annotated with thread_pce and xpce…

If somebody could give me some hints or directions, it would be a great help… thanx: Imre

Links for those needing them.

Contralog: a Prolog conform forward-chaining environment and its application for dynamic programming and natural language parsing. (pdf)

CYK - In computer science, the Cocke–Younger–Kasami algorithm (alternatively called CYK , or CKY ) is a parsing algorithm for context-free grammars, named after its inventors, John Cocke, Daniel Younger and Tadao Kasami. (Wikipedia)

1 Like

Please try the current development versions. Some of this sounds familiar :slight_smile:

thanx Jan for the quick response…

Actually I have also tried with 8.3.6-1 (downloaded yesterday), but nothing changed… I also checked some similar conversations, but none of them gave me an impression…
(some thoughts, not yet verified: 1. maybe the hook term_expansion is searched in another order? 2. maybe the implementation of @/2 changed so, that the module being applied, remains longer, and this is why it doesn’t find obvious definitions in the actually consulted module?)

  • question: where can I find a 7.x distribution, if I want to fall back?

Imre

AFAIK the older versions are not retained as builds. However access to the source via release is possible. See GitHub releases for stable

Quite a few older versions become visible if you click the Show all files at the bottom of the download table.

Indeed, for the source all releases are available in the GIT repo and are tagged with VN.N.N, e.g., V7.6.4.

I personally prefer fixing such issues though … I’ll have a closer look later.

2 Likes

Somewhat more context. Most code, including most internal libraries are now autoloaded. This typically gives a few issues, but there is one exception to this: term/goal expansion.

If the term/goal expansion rules uses code that needs to be autoloaded but is written such that the code that needs to be autoloaded is also expanded by the same rule we get into a loop. This should normally lead to a warning about an autoload loop. I don’t see that in your message.

There are several solutions:

  • Add some condition to the rule that ensures it is not triggered on the autoloaded code.

  • Load the required code explicitly. There is a problem here with indirect dependencies. These will still be autoloaded. This needs to be addressed at some point.

  • Disable autoloading (temporary or forever) using

    :- set_prolog_flag(autoload, false).
    

Hope this is the problem. First step is probably the last. If that helps you know autoloading is the problem and you can decide how to deal with it.

Thanx Jan, I’ll try it… The messages I had given yesterday, are only an extract (small percent) of the actual messages… One more hint: if I try to consult not the entire software, but only the one that is written in Contralog (enParsertry,pl that applies term_expansion definitions in clog.pl), I get a much simpler error… see below. And the first three lines are resembling to another issue in https://www.bountysource.com/issues/91864443-autoload-loop-error-for-lists-must_be-2 — this is important, because that case is still more distilled as in my case. Have you ever read that case?

ERROR: autoload loop:
ERROR:   clog:debug/3
ERROR:   clog:debug/3
ERROR: c:/program files/swipl/library/debug.pl:0:
ERROR:    clog:declDynDiscontiguous/2: Unknown procedure: clog:debug/3
ERROR:      However, there are definitions for:
ERROR:            clog:debug/0
ERROR: //he202171e001.emea2.cds.t-internal.com/a94537187$/home/data/prologserver/enparse/enparsertry.pl:651:
ERROR:    Domain error: `module_file' expected, found `'c:/program files/swipl/library/apply.pl''
ERROR: //he202171e001.emea2.cds.t-internal.com/a94537187$/home/data/prologserver/enparse/enparsertry.pl:1915:
ERROR:    '$eval_if'/1: Unknown procedure: clog:switchOut/0
ERROR:      However, there are definitions for:
ERROR:            enParser:switchOut/0

Nope. There is so little context that it is hard to comment anyway.

So, it seems clog should have this (or the use_module/2 version to only import debug/3).

:- use_module(library(debug)).

In recent versions (not sure whether that is already in 8.2) there are some extra commands in the PceEmacs editor to help you with modules and dependencies:

  • ^c^o – Add module header to the file if there is none (else report the name of the module)
  • ^c^d – Add missing dependencies. How this is done depends on a preference or already present dependencies, i.e., using use_module/1, use_module/2, autoload/1 or autoload/2.
  • ^c^e – Add the current predicate to the module export list.

Thanx, Jan, with your hints I could get along…
(At least my imports are made everywhere explicite!)
Imre