built-in predicate

logtalk_library_path/2

Description

logtalk_library_path(Library, Path)

Dynamic and multifile user-defined predicate, allowing the declaration of aliases to library paths. Library aliases may also be used on the second argument (using the notation alias(path)). Paths must always end with the path directory separator character ('/').

Warning

Library aliases should be unique. The logtalk_make/1 built-in predicate can be used to detect and report duplicated library aliases using the check target.

Clauses for this predicate should preferably be facts. Defining rules to dynamically compute at runtime both library alias names and their paths, although sometimes handy, can inadvertently result in endless loops when those rules also attempt to expand library paths. When asserting facts for this predicate, use preferably asserta/1 instead of assertz/1 to help ensure the facts will be used before any rules.

Relative paths (e.g. '../' or './') should only be used within the alias(path)) notation so that library paths can always be expanded to absolute paths independently of the (usually unpredictable) current directory at the time the logtalk_library_path/2 predicate is called.

When working with a relocatable application, the actual application installation directory can be retrieved by calling the logtalk_load_context/2 predicate with the directory key and using the returned value to define the logtalk_library_path/2 predicate. On a settings file file or a loader file file, simply use an initialization/1 directive to wrap the call to the logtalk_load_context/2 predicate and the assert of the logtalk_library_path/2 fact.

This predicate may be used to override the default scratch directory by defining the library alias scratch_directory in a backend Prolog initialization file (assumed to be loaded prior to Logtalk loading). This allows e.g. Logtalk to be installed in a read-only directory by setting this alias to the operating-system directory for temporary files. It also allows several Logtalk instances to run concurrently without conflict by using a unique scratch directory per instance (e.g. using a process ID or a UUID generator).

This predicate may be used to override the default location used by the packs tool to store registries and packs by defining the logtalk_packs library alias in settings file or in a backend Prolog initialization file (assumed to be loaded prior to Logtalk loading).

The logtalk built-in object provides an expand_library_path/2 predicate that can be used to expand library aliases and files expressed using library notation.

Modes and number of proofs

logtalk_library_path(?atom, -atom) - zero_or_more
logtalk_library_path(?atom, -compound) - zero_or_more

Errors

(none)

Examples

:- initialization((
   logtalk_load_context(directory, Directory),
   asserta(logtalk_library_path(my_application_root, Directory))
)).
| ?- logtalk_library_path(viewpoints, Path).

Path = examples('viewpoints/')
yes

| ?- logtalk_library_path(Library, Path).

Library = home,
Path = '$HOME/' ;

Library = logtalk_home,
Path = '$LOGTALKHOME/' ;

Library = logtalk_user
Path = '$LOGTALKUSER/' ;

Library = examples
Path = logtalk_user('examples/') ;

Library = library
Path = logtalk_user('library/') ;

Library = viewpoints
Path = examples('viewpoints/')
yes
| ?- logtalk::expand_library_path(viewpoints, Path).

Path = '/Users/pmoura/logtalk/examples/viewpoints/'.
yes

| ?- logtalk::expand_library_path(viewpoints('loader.lgt'), Path).

Path = '/Users/pmoura/logtalk/examples/viewpoints/loader.lgt'.
yes