/usr/lib/swi-prolog/library/dialect/ciao.pl is in swi-prolog-nox 5.10.4-3ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | /* Part of SWI-Prolog
Author: Jan Wielemaker
E-mail: J.Wielemaker@uva.nl
WWW: http://www.swi-prolog.org
Copyright (C): 2009, University of Amsterdam
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
As a special exception, if you link this library with other files,
compiled with a Free Software compiler, to produce an executable, this
library does not by itself cause the resulting executable to be covered
by the GNU General Public License. This exception does not however
invalidate any other reasons why the executable file might be covered by
the GNU General Public License.
*/
:- module(ciao,
[
]).
:- use_module('../error').
:- use_module('../apply').
:- use_module('../debug').
/** <module> Ciao Prolog compatibility module
This module sets up support for loading Ciao Prolog modules that start
with a :- module(Name, Exports, Packages) directive. Upon encountering
this directive, it is rewritten into a SWI-Prolog module declaration,
followed by a series of directives to setup Ciao compatibility.
Typical usage for loading Ciao code is:
==
:- use_module(library(dialect/ciao)).
==
@tbd Create much more of the Ciao infrastructure.
*/
:- multifile
system:goal_expansion/2,
system:term_expansion/2,
user:file_search_path/2.
/*******************************
* PATHS *
*******************************/
user:file_search_path(engine, library(dialect/ciao/engine)).
/*******************************
* MODULES & DECLARATIONS *
*******************************/
:- multifile
declaration/1. % Head
system:term_expansion((:- module(Name, Public, Packages)),
[ (:- module(Name, Public)),
(:- style_check(-atom)),
(:- style_check(-singleton)),
(:- expects_dialect(ciao))
| Directives
]) :-
maplist(package_directive, Packages, Directives).
system:term_expansion((:- use_package(Name)),
(:- include(library(Name)))).
system:term_expansion((:- new_declaration(Name/Arity)),
ciao:declaration(Head)) :-
functor(Head, Name, Arity).
system:term_expansion((:- Decl), Exp) :-
declaration(Decl),
( functor(Decl, Name, Arity),
prolog_load_context(module, Module),
current_predicate(Module:Name/Arity)
-> Exp = (:- Decl)
; Exp = []
).
system:term_expansion((:- meta_predicate(CiaoSpec)),
[ (:- meta_predicate(SWISpec))
| Wrappers
]) :-
prolog_load_context(dialect, ciao),
( phrase(map_metaspecs(CiaoSpec, SWISpec), Wrappers)
-> true
; debug(ciao, 'Failed to translate ~q',
[(:- meta_predicate(CiaoSpec))]),
fail
).
package_directive(Package, Directive) :-
expand_term((:- use_package(Package)), Directive).
%% map_metaspecs(+CiaoSpec, -SWISpec)// is det.
%
% Map a Ciao meta-predicate to a SWI-Prolog one.
%
% @see http://clip.dia.fi.upm.es/Software/Ciao/ciao_html/ciao_14.html
map_metaspecs(Var, _) -->
{ var(Var), !,
instantiation_error(Var)
}.
map_metaspecs((A0,B0), (A,B)) --> !,
map_metaspecs(A0, A),
map_metaspecs(B0, B).
map_metaspecs(Head0, Head) -->
{ \+ (arg(_, Head0, S), S==addmodule), !,
Head0 =.. [Name|Args0],
maplist(map_metaspec, Args0, Args),
Head =.. [Name|Args]
}.
map_metaspecs(Head0, Head) -->
{ functor(Head0, Name, Arity),
functor(HeadIn, Name, Arity),
HeadIn =.. [Name|ArgsIn],
Head0 =.. [Name|Args0],
map_mspec_list(Args0, Args, M, ArgsIn, ArgsOut),
Head =.. [Name|Args],
HeadOut =.. [Name|ArgsOut]
},
[ (:- module_transparent(Name/Arity)),
(HeadIn :- context_module(M), HeadOut)
].
map_metaspec(Var, ?) :-
var(Var), !.
map_metaspec(goal, 0).
map_metaspec(clause, :).
map_metaspec(fact, :).
map_metaspec(spec, :).
map_metaspec(pred(N), N).
map_metaspec(?, ?).
map_metaspec(+, +).
map_metaspec(-, -).
map_mspec_list([], [], _, [], []).
map_mspec_list([S0|TA0], [S|TA], M, [O|OT0], [O|OT]) :-
map_metaspec(S0, S), !,
map_mspec_list(TA0, TA, M, OT0, OT).
map_mspec_list([addmodule|TA0], TA, M, [O|OT0], [O,M|OT]) :- !,
map_mspec_list(TA0, TA, M, OT0, OT).
/*******************************
* LIBRARY SETUP *
*******************************/
%% push_ciao_library
%
% Pushes searching for dialect/ciao in front of every library
% directory that contains such as sub-directory.
push_ciao_library :-
( absolute_file_name(library(dialect/ciao), Dir,
[ file_type(directory),
access(read),
solutions(all),
file_errors(fail)
]),
asserta((user:file_search_path(library, Dir) :-
prolog_load_context(dialect, ciao))),
fail
; true
).
:- push_ciao_library.
|