YAP 7.1.0
imports.yap
1/*************************************************************************
2* *
3* YAP Prolog *
4* *
5* Yap Prolog was developed at NCCUP - Universidade do Porto *
6* *
7* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
8* *
9****************
10* *
11*************************************************************************/
12
13/**
14 *
15 * @ file imports.yap
16 *
17 * this file implements search for available predicates for the current module. Search can be called
18 * at compile-time or at run-time.
19 *
20 * @defgroup PImport Predicate Import Mechanism
21 *
22 * @{
23 *
24 * The import mechanism is as follows:
25 * - built-ina (module prolog)
26 * - explicit imports (import table).
27 * - parent module mechanism.
28 * - SWI auto-loader.
29 */
30
31:- '$mk_dynamic'( prolog:'$parent_module'(_,_)).
32% You can have a default parent (user)
33% '$across_modules'(_:G, Visited, ExportingMod:G) :-
34% current_prolog_flag(default_parent_module, ExportingModuleI),
35% recorded('$module','$module'( _, ExportingModuleI, _, _, Exports), _),
36% lists:member(G, Exports),
37% \+ lists:member(ExportingModuleI:G, Visited),
38% '$check_definition'(ExportingModuleI:G, [ExportingModuleI:G|Visited], ExportingMod:G).
39% % parent module mechanism
40% '$across_modules'(ImportingMod:G, Visited, ExportingMod:G ) :-
41% '$parent_module'(ImportingMod,ExportingModI),
42% recorded('$module','$module'( _, ExportingModI, _, _, Exports), _), lists:member(G, Exports),
43% \+ lists:member(ExportingModI:G, Visited),
44% '$check_definition'(ExportingModI , [ExportingModI:G|Visited], ExportingMod:G).
45% % autoload
46% '$across_modules'(_ImportingMod:G, Visited, ExportingMod:G ) :-
47% recorded('$dialect',swi,_),
48% fail,
49% prolog_flag(autoload, true),
50% prolog_flag(unknown, _OldUnk, fail),
51% (
52% recorded('$module','$module'( _, autoloader, _, _, _Exports), _)
53% ->
54% true
55% ;
56% use_module(library(autoloader))
57% ;
58% true
59% ),
60% autoload(G, _File, ExportingModI),
61% \+ lists:member(ExportingModI:G, Visited),
62% '$check_definition'(ExportingModI:G , [ExportingModI:G|Visited], ExportingMod:G).
63
64% be careful here not to generate an undefined exception.
65'$imported_predicate'(G, _ImportingMod, G, prolog) :-
66 nonvar(G), '$is_system_predicate'(G, prolog), '$is_system_predicate'.
67'$imported_predicate'(G, ImportingMod, G0, ExportingMod) :-
68 nonvar(G),
69 '$follow_import_chain'(ImportingMod,G,ExportingMod,G0).
70
71
72
nonvar( T)