Source Files

The Prolog system maintains a table of consulted source files in each knowledge base. The entries in this table have a longer life cycle than the entries in the stream alias table. When a named stream is closed, the alias is removed from the alias table and thus the stream properties are not anymore accessible via the alias. On the other hand when a source file is closed after consult, the entry in the source file table is not removed.

For a verbose consult, ensure loaded or unload the source also keeps a property with the timing of the operation. The timing is suspended when a source consults or ensure loads another source, so that the property only shows the time spent in the given source. Further a source records the other sources that this source has been consulted or ensure loaded. This way a graph of the sources and their dependency is built.

Each source has an individual lock. This lock serializes the predicate lookup, the operator lookup, the consult and the purge of sources by multiple threads. If multiple threads access sources that depend on each other this locking might cause a deadlock, since we do not the release the lock between a source and its imports. Deadlocks are detected by a timeout which can be controlled by the sys_timeout Prolog flag.

The source dependency graph is allowed to have cycles. During consult or ensure loaded a thread only processes each source once, so that there is no danger of duplicate imports or an infinite import loop. The dependency graph is also used by a mark and sweep algorithm to unload unused sources. The user and system source does play an important role here, it determines the root for the marking of the sources.

The following source file predicates are provided:

current_source(S):
The predicate succeeds for the user absolute source paths S.
source_property(S, P):
The predicate succeeds for the properties P of the source path S.
set_source_property(S, P):
The predicate assigns the property P to the source path S.
reset_source_property(S, P):
The predicate deassigns the property P from the source path S.
sys_current_resource(P):
Succeeds for every member P of the list of error resources.
current_module(M):
The predicate succeeds for the modules M.
sys_context_property(C, Q):
The predicate succeeds for the context property Q of the callable C.
sys_set_context_property(B, Q, A):
The predicate succeeds for a new callable B which is a clone of the callable A with the context property Q.

The following source properties for source files are provided:

sys_capability(P):
The property indicates that the source has the parent capability P. The property cannot be changed.
last_modified(L):
The property indicates that the source was last modified at date L. The date is given in milliseconds since January 1, 1970 GMT. An undefined date is indicated by the value 0. The property cannot be changed.
version_tag(V):
The property indicates that the source has the version tag V. The version tag is an atom which starts and ends with double quotes (“). An undefined version tag is indi-cated by the empty string. The property cannot be changed.
expiration(E):
The property indicates that the source will expire at the date E. The date is given in milliseconds since January 1, 1970 GMT. An undefined date is indicated by the value 0. The property cannot be changed.
date(E):
The property indicates that the source was requested at the date E. The date is given in milliseconds since January 1, 1970 GMT. An undefined date is indicated by the value 0. The property cannot be changed.
max_age(E):
The property indicates that the max age of the source in seconds. An undefined max age is indicated by the value -1. The property cannot be changed.
short_name(S):
The property indicates that the source has the short name S. The property cannot be changed.

Kommentare