Make / 0 for SICStus

How can I guarantee that all modules (and, ideally, all other files that have been downloaded or included) are updated? When release use_module(mymodule) SICStus compares the modification date of the mymodule.pl file and reloads it if it is newer. In addition, include -ed files will cause recompilation. But it does not double-check all the modules used by mymodule .

Brief information, how can I get similar functionality, since SWI offers it with make/0 ?

+3
source share
2 answers

There is nothing in SICStus Prolog that provides such functionality.

The big problem is that the current Prologs are too dynamic for something like make / 0 to work reliably, except in very simple cases. With features such as a term extension, goals that are performed during the download (including goals for downloading files that are shared), etc., you cannot learn how to reliably overload files. I did not look closely at it, but supposedly making / 0 in SWI Prolog has the same problem.

Usually I just restart the Prolog process and upload the β€œmain” file again, i.e. file that downloads everything i need.

PS. I was unable to get the formatting of the code in the comments, so I put it here: An example of why make / 0 needs to be protected from the "user" as a file from current_module / 2:

 | ?- [user]. % compiling user... | :- module(m,[p/0]). p. end_of_file. % module m imported into user % compiled user in module m, 0 msec 752 bytes yes | ?- current_module(M, F), F==user. F = user, M = m ? ; no | ?- 
+5
source

So far I have lived with several hacks:

Up to 0.7 - time before module

SICStus always had ensure_loaded/1 beginning of Quintus, which was not only a directive (as in ISO), but also a command. So I wrote my own make predicate, simply listing all the files:

 l :- ensure_loaded([f1,f2,f3]). 

After graduation l. only those files that were changed at this time were rebooted.

Perhaps I could write it the same way - I would read the middle (sic):

 l :- \+ ( source_file(F), \+ ensure_loaded(F) ). 

3.0 - Modules

With modules, things have changed a bit. On the one hand, there were files downloaded manually into the module, for example ensure_loaded(module:[f1,f2,f3]) , and then those that were pure modules. It turned out that there is a way to globally ensure module loading - without interfering with the actual import lists, simply by specifying use_module(m1, []) , which again is a directive and a command. A point is an empty list that made the module double-check and reload, but thanks to empty lists this operator could be done everywhere.

In the meantime, I am using the following module:

 :- module(make,[make/0]). make :- \+ ( current_module(_, F), \+ use_module(F, []) ). 

This works for all β€œlegitimate” modules β€” and until the interfaces change. I still don't like this verbosity: for each module being tested and unmodified, there is one line of message. Therefore, I get a page with such messages when I just want to check that everything is updated. Ideally, such messages will only be displayed if something new happens.

 | ?- make. % module m2 imported into make % module m1 imported into make % module SU_messages imported into make yes | ?- make. % module m2 imported into make % module m1 imported into make % module SU_messages imported into make yes 

the improved version takes into account @PerMildner's note.

Other files may be reloaded if they are associated with only one module. In particular, uploading files to the user module is enabled as .sicstusrc . See the link above for the full code.

  % reload files that are implicitly modules, but that are still simple to reload \+ ( source_file(F), F \== user, \+ current_module(_, F), % not officially declared as a module setof(M, P^ExF^ExM^( source_file(M:P,F), \+ current_module(M,ExF), % not part of an official module \+ predicate_property(M:P,multifile), \+ predicate_property(M:P,imported_from(ExM)) ),[M]), % only one module per file, others are too complex \+ ensure_loaded(M:F) ). 

Note that in SWI, do not ensure_loaded/1 and use_module/2 compare file modification dates. Therefore, both of them cannot be used to ensure that the latest version of the file is downloaded.

+3
source

Source: https://habr.com/ru/post/1246098/


All Articles