Modules as blobs

Author(s): Isabel Garcia-Contreras, Jose F. Morales.

This module implements (temporary) modules-as-blobs facilities. They allow the runtime creation of modules from strings and terms.

Implementation

Run-time creation of modules is currently implemented by writing the module code into a unique temporary directory (using the system mktemp_in_tmp/2 predicate).

Currently they need to be deleted explicitly.

Note that this is a temporary solution before read/write stream operations can be work on in-memory objects.

Examples

The predicate new_modblob/4 creates a new temporary module, that can be deleted with delete_modblob/1.

Module creation requires the module name, export list, program clauses, and returns the module object (currently a path). If a module directive is specified, the export list is ignored.

Example:

?- new_modblob([(p(A) :- q(A)), (q(b))], [p/1], my_tmp_mod, ModBlob), modblob_path(ModBlob, Path).
Path = '/tmp/tmp_modsfbMY9Y/my_tmp_mod.pl' ?

where the contents of /tmp/tmp_modsfbMY9Y/my_tmp_mod.pl are:

:-module(_,[p/1],[]).
p(A) :-
    q(A).
q(b).

Usage and interface

Documentation on exports

PREDICATEnew_modblob/4

Usage:new_modblob(Clauses,ExportedPreds,ModName,ModBlob)

Write clauses Clauses in a temporary module identified by ModBlob.

Usage:delete_modblob(ModBlob)

Removes the data associated to ModBlob

  • The following properties should hold at call time:
    (modblobs:modblob/1)ModBlob is a is a temporary module object
  • The following properties should hold globally:
    (native_props:is_det/1)All calls of the form delete_modblob(ModBlob) are deterministic.

Usage:modblob_path(ModBlob,ModPath)

Obtain the temporary file associated to ModBlob

  • The following properties should hold at call time:
    (basic_props:atm/1)ModBlob is an atom.
  • The following properties should hold upon exit:
    (basic_props:atm/1)ModPath is an atom.

Documentation on imports

This module has the following direct dependencies: