1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
5
<TITLE>SWI-Prolog 5.6.47 Reference Manual: Section 3.2</TITLE><LINK REL=home HREF="index.html">
6
<LINK REL=contents HREF="Contents.html">
7
<LINK REL=index HREF="DocIndex.html">
8
<LINK REL=previous HREF="projectfiles.html">
9
<LINK REL=next HREF="editreload.html">
10
<STYLE type="text/css">
11
/* Style sheet for SWI-Prolog latex2html
19
{ background-color: #c5e1ff;
29
background-color: #f8f8f8;
34
background-color: #f0f0f0;
53
background-color: #f0f0f0;
56
margin-left: 10%; margin-right:10%;
109
sup.fn { color: blue; text-decoration: underline; }
110
span.fn-text: { display: none; }
111
sup.fn span {display: none;}
113
{ display: block !important;
114
position: absolute; top: auto; left: auto; width: 80%;
115
color: #000; background: white;
117
padding: 5px; margin: 10px; z-index: 100;
122
<BODY BGCOLOR="white">
123
<DIV class="navigate"><A class="nav" href="index.html"><IMG SRC="home.gif" BORDER=0 ALT="Home"></A>
124
<A class="nav" href="Contents.html"><IMG SRC="index.gif" BORDER=0 ALT="Contents"></A>
125
<A class="nav" href="DocIndex.html"><IMG SRC="yellow_pages.gif" BORDER=0 ALT="Index"></A>
126
<A class="nav" href="projectfiles.html"><IMG SRC="prev.gif" BORDER=0 ALT="Previous"></A>
127
<A class="nav" href="editreload.html"><IMG SRC="next.gif" BORDER=0 ALT="Next"></A>
130
<H2><A NAME="sec:3.2"><SPAN class="sec-nr">3.2</SPAN> <SPAN class="sec-title">Using
131
modules</SPAN></A></H2>
133
<A NAME="sec:usingmodules"></A>
135
<P>Modules have been debated fiercely in the Prolog world. Despite all
136
counter-arguments we feel they are extremely useful because
140
<LI><I>They hide local predicates</I><BR>
141
This is the reason they have been invented in the first place. Hiding
142
provides two features. They allow for short predicate names without
143
worrying about conflicts. Given the flat name-space introduced by
144
modules, they still require meaningful module names as well as
145
meaningful names for exported predicates.
148
<LI><I>They document the interface</I><BR>
149
Possibly more important then avoiding name-conflicts is their role in
150
documenting which part of the file is for public usage and which is
151
private. When editing a module you may assume you can reorganise
152
anything but the name and semantics of the exported predicates without
156
<LI><I>They help the editor</I><BR>
157
The PceEmacs built-in editor does on-the-fly cross-referencing of the
158
current module, colouring predicates based on their origin and usage.
159
Using modules, the editor can quickly find out what is provided by the
160
imported modules by reading just the first term. This allows it to
161
indicate real-time which predicates are not used or not defined.
164
<P>Using modules is generally easy. Only if you write meta-predicates
165
(predicates reasoning about other predicates) that are exported from a
166
module good understanding of resolution of terms to predicates inside a
167
module is required. Here is a typical example from <CODE>library(readutil)</CODE>.
171
[ read_line_to_codes/2, % +Fd, -Codes
172
read_line_to_codes/3, % +Fd, -Codes, ?Tail
173
read_stream_to_codes/2, % +Fd, -Codes
174
read_stream_to_codes/3, % +Fd, -Codes, ?Tail
175
read_file_to_codes/3, % +File, -Codes, +Options
176
read_file_to_terms/3 % +File, -Terms, +Options
b'\\ No newline at end of file'