YAP 7.1.0
pathconf.yap
1/**
2 @defgroup pathconf Configuration of the Prolog file search path
3 @ingroup AbsoluteFileName
4
5 Prolog systems search follow a complex search on order to track down files.
6
7@{
8**/
9:- module(user).
10
11/**
12@pred library_directory(?Directory:atom) is nondet, dynamic
13
14Dynamic, multi-file predicate that succeeds when _Directory_ is a
15current library directory name. Asserted in the user module.
16
17Library directories are the places where files specified in the form
18`library( _File_ )` are searched by the predicates consult/1,
19reconsult/1, use_module/1, ensure_loaded/1, and load_files/2.
20
21This directory is initialized by a rule that calls the system predicate
22system_library/1.
23*/
24:- multifile library_directory/1.
25
26:- dynamic library_directory/1.
27%% Specifies the set of directories where
28% one can find Prolog libraries.
29%
30library_directory(Home) :-
31 current_prolog_flag(prolog_library_directory, Home),
32 Home \= ''.
33% 1. honor YAPSHAREDIR
34library_directory( Dir ) :-
35 getenv( 'YAPSHAREDIR', Dir).
36%% 2. honor user-library
37library_directory( '~/share/Yap' ).
38%% 3. honor current directory
40%% 4. honor default location.
41library_directory( Dir ) :-
42 system_library( Dir ).
43
44/**
45 @pred commons_directory(? _Directory_:atom) is nondet, dynamic
46
47 State the location of the Commons Prolog Initiative.
48
49 This directory is initialized as a rule that calls the system predicate
50 library_directories/2.
51 */
52:- dynamic commons_directory/1.
53
54:- multifile commons_directory/1.
55
56
57commons_directory( Path ):-
58 system_commons( Path ).
59
60/**
61 @pred foreign_directory(? _Directory_:atom) is nondet, dynamic
62
63 State the location of the Foreign Prolog Initiative.
64
65 This directory is initialized as a rule that calls the system predicate
66 library_directories/2.
67*/
68
69:- multifile foreign_directory/1.
70
71:- dynamic foreign_directory/1.
72
73%foreign_directory( Path ):-
74foreign_directory(Home) :-
75 current_prolog_flag(prolog_foreign_directory, Home),
76 Home \= ''.
78 current_prolog_flag(windows, true),
79 file_search_path(path, C).
81foreign_directory(yap('lib/Yap')).
82%foreign_directory( Path ):-
83% system_foreign( Path ).
84
85/**
86 @pred prolog_file_type(?Suffix:atom, ?Handler:atom) is nondet, dynamic
87
88 This multifile/dynamic predicate relates a file extension _Suffix_
89 to a language or file type _Handler_. By
90 default, it supports the extensions yap, pl, and prolog for prolog files and
91 uses one of dll, so, or dylib for shared objects. Initial definition is:
92
93```prolog
94 prolog_file_type(yap, prolog).
95 prolog_file_type(pl, prolog).
96 prolog_file_type(prolog, prolog).
97 prolog_file_type(qly, prolog).
98 prolog_file_type(qly, qly).
99 prolog_file_type(A, prolog) :-
100 current_prolog_flag(associate, A),
101 A \== prolog,
102 A \==pl,
103 A \== yap.
104 prolog_file_type(A, executable) :-
105 current_prolog_flag(shared_object_extension, A).
106 prolog_file_type(pyd, executable).
107```
108*/
109
110:- dynamic prolog_file_type/2.
111
112prolog_file_type(yap, prolog).
113prolog_file_type(pl, prolog).
114prolog_file_type(prolog, prolog).
115prolog_file_type(A, prolog) :-
116 current_prolog_flag(associate, A),
117 A \== current_prolog_flag,
118 A \== current_prolog_flag,
119 A \== current_prolog_flag.
120prolog_file_type(qly, qly).
121prolog_file_type(A, executable) :-
122 current_prolog_flag(shared_object_extension, A).
123 prolog_file_type(pyd, executable).
124
125/**
126 @pred file_search_path(+Name:atom, -Directory:atom) is nondet
127
128 Allows writing file names as compound terms. The _Name_ and
129 _DIRECTORY_ must be atoms. The predicate may generate multiple
130 solutions. The predicate is originally defined as follows:
131
132```prolog
133file_search_path(library, Dir) :-
134 library_directory(Dir).
135file_search_path(commons, Dir) :-
136 commons_directory(Dir).
137file_search_path(swi, Home) :-
138 current_prolog_flag(home, Home).
139file_search_path(yap, Home) :-
140 current_prolog_flag(home, Home).
141file_search_path(system, Dir) :-
142 prolog_flag(host_type, Dir).
143file_search_path(foreign, Dir) :-
144 foreign_directory(Dir).
145file_search_path(executable, Dir) :-
146 foreign_directory(Dir).
147file_search_path(path, C) :-
148 ( getenv('PATH', A),
149 ( current_prolog_flag(windows, true)
150 -> atomic_list_concat(B, ;, A)
151 ; atomic_list_concat(B, :, A)
152 ),
153 lists:member(C, B)
154 ).
155
156```
157
158 Thus, `compile(library(A))` will search for a file using
159 library_directory/1 to obtain the prefix,
160 whereas 'compile(system(A))` would look at the `host_type` flag.
161
162*/
163:- multifile file_search_path/2.
164
165:- dynamic file_search_path/2.
166
167
168file_search_path(library, Dir) :-
170file_search_path(commons, Dir) :-
172file_search_path(swi, Home) :-
173 current_prolog_flag(home, Home).
174file_search_path(yap, Home) :-
175 current_prolog_flag(home, Home).
176file_search_path(system, Dir) :-
177 prolog_flag(host_type, Dir).
178file_search_path(foreign, Dir) :-
180file_search_path(executable, Dir) :-
182file_search_path(path, C) :-
183 ( getenv('PATH', A),
184 ( current_prolog_flag(windows, true)
185 -> atomic_list_concat(B, ;, A)
186 ; atomic_list_concat(B, :, A)
187 ),
188 lists:member(C, B)
189 ).
190
191
192%% @}
193
atomic_list_concat(+ As,? A)
atomic_list_concat(? As,+ Separator,? A)
current_prolog_flag(? Flag,- Value)
member(?Element, ?Set) is true when Set is a list, and Element occurs in it
commons_directory(? Directory:atom)
file_search_path(+Name:atom, -Directory:atom)
foreign_directory(? Directory:atom)
library_directory(?Directory:atom)
prolog_file_type(?Suffix:atom, ?Handler:atom)