Subject: Re: How to build a Runtime which loads a *.qlf ?

From: Jan Wielemaker <[email-masked]>
Date: Fri, 18 Feb 2000 09:40:19 +0100

On Thu, 17 Feb 2000, you wrote:
>Jan Wielemaker schrieb:
>
>> First the remark: the runtime system was never meant to load code
>> besides simple rule-bases, configuration, etc. at runtime 
>
>Bad news, Prolog in combination with XPCE seduce to a disign like
>mine.
>
>> My suggestion is *not* to use any of the standard loading primitives
>> to refer to parts of the kernel.  Instead, use the upcomming ISO
>> stuff, where not the name of the file, but the name of the module
>> matters.  I would write:
>> 
>> :- meta_predicate
>>         import_module(:).
>> 
>> import_module(Spec) :-
>>         strip_module(Spec, Into, Module),
>>         (   predicate_property(Head, exported(Module)),
>
>--        (   predicate_property(Head, exported(Module)),
>++        (   Module:predicate_property(Head, exported),
>
>>             Into:import(Module:Head),
>>             fail
>>         ;   true
>>         ).
>

Actually:

	predicate_property(Module:Head, exported(Module)),
	
(is the same, but more elegantly).

>Ufff, the runtime version work with the change above and many others.
>
>Many thanks to you.
>
>What I am missing in the specification of import_module/1 is a kind
>of loading for the specified module if it isn't loaded. But i think 
>this fails by the missing knowledge about the relation between the module-
>and the filename.

You should use the import_module to refer to modules that are part of
the development system (i.e. libraries) and you should make sure they
are loaded into the runtime.  You can (should) use use_module for
files you distribute with your application.

>Do you know what ISO will say to this ?
>What is your advice ?

The proposed module system for ISO is very different from the syntax
point of view.  The execution model is very close.  One difference
though is that the argument to use_module/1 is the name of a module,
rather than the name of a file.  The also split a module into its
signature and body and allow for multiple modules in one file.

One big problem is that they partially use the same predicate names
with different semantics.  Sofar I haven't thought a lot about providing
ISO compliant module system.  I'll first wait for the proposal to
settle.

>> >- use_module is a very nice thing for development but in a runtime
>> >  version of a qlf file it causes the warning
>> >  "directive failed: frage:use_module ..."
>> >  I'll like to have the use_module's in the file to consult and test
>> >  this single file.
>> >
>> >  I'll solved this with
>> >
>> >    (   feature(runtime, true)
>> >    ->  redefine_system_predicate(use_module(_)),
>> >        asserta(use_module(_))
>> >
>
>Is this a good idea ? What is your advice ?

Generally, use your own predicate name and define that in module user
to make a call depending on the runtime flag (now current_prolog_flag/2,
feature/2 is compatibility only).

>> >
>> >import/1: pce_util:chain_list/2 is not declared public (still imported)
>
>How should I interpret this message ?
>It seems that it was *not* imported.

It means that chain_list/2 is not in the export list of pce_util.  This
can mean three things: the module doesn't exist (isn't yet loaded), the
module doesn't have the predicate in ints export list or it doesn't
define the predicate at all.

import/2 will create the missing bits and a reference link.  This means
that if the module does not exist, an empty module with an undefined
predicate is created that is imported.  If the predicate gets a
definition later all should work as expected.

	Regards --- Jan