File: gprolog021.html

package info (click to toggle)
gprolog 1.3.0-6.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 13,512 kB
  • ctags: 8,954
  • sloc: ansic: 57,431; perl: 16,620; sh: 5,900; makefile: 1,284
file content (384 lines) | stat: -rw-r--r-- 15,438 bytes parent folder | download | duplicates (2)
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="gprolog.css">
<TITLE>
Prolog directives
</TITLE>
</HEAD>
<BODY TEXT=black BGCOLOR=white>
<A HREF="gprolog020.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="gprolog022.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H3 CLASS="subsection"><A NAME="htoc45">6.1</A>&nbsp;&nbsp;Prolog directives</H3><UL>
<LI><A HREF="gprolog021.html#toc26">Introduction</A>
<LI><A HREF="gprolog021.html#toc27"><TT>dynamic/1</TT></A>
<LI><A HREF="gprolog021.html#toc28"><TT>public/1</TT></A>
<LI><A HREF="gprolog021.html#toc29"><TT>multifile/1</TT></A>
<LI><A HREF="gprolog021.html#toc30"><TT>discontiguous/1</TT></A>
<LI><A HREF="gprolog021.html#toc31"><TT>ensure_linked/1</TT></A>
<LI><A HREF="gprolog021.html#toc32"><TT>built_in/0</TT>,
 <TT>built_in/1</TT>,
 <TT>built_in_fd/0</TT>,
 <TT>built_in_fd/1</TT></A>
<LI><A HREF="gprolog021.html#toc33"><TT>include/1</TT></A>
<LI><A HREF="gprolog021.html#toc34"><TT>ensure_loaded/1</TT></A>
<LI><A HREF="gprolog021.html#toc35"><TT>op/3</TT></A>
<LI><A HREF="gprolog021.html#toc36"><TT>char_conversion/2</TT></A>
<LI><A HREF="gprolog021.html#toc37"><TT>set_prolog_flag/2</TT></A>
<LI><A HREF="gprolog021.html#toc38"><TT>initialization/1</TT></A>
<LI><A HREF="gprolog021.html#toc39"><TT>foreign/2</TT>,
 <TT>foreign/1</TT></A>
</UL>

<A NAME="toc26"></A>
<H4 CLASS="subsubsection"><A NAME="htoc46">6.1.1</A>&nbsp;&nbsp;Introduction</H4>
Prolog directives are annotations inserted in Prolog source files for the
compiler. A Prolog directive is used to specify:
<UL CLASS="itemize"><LI CLASS="li-itemize">the properties of some procedures defined in the source file.<BR>
<BR>
<LI CLASS="li-itemize">the format and the syntax for read-terms in the source file (using
changeable Prolog flags).<BR>
<BR>
<LI CLASS="li-itemize">included source files.<BR>
<BR>
<LI CLASS="li-itemize">a goal to be executed at run-time.</UL>
<A NAME="toc27"></A>
<H4 CLASS="subsubsection"><A NAME="htoc47">6.1.2</A>&nbsp;&nbsp;<TT>dynamic/1</TT></H4>
<A NAME="dynamic/1"></A>
 
<B>Templates</B>
<DL CLASS="list" COMPACT="compact"><DT CLASS="dt-list"><DD CLASS="dd-list"><TT>
dynamic(+predicate_indicator)<BR>
dynamic(+predicate_indicator_list)<BR>
dynamic(+predicate_indicator_sequence)</TT></DL>
<B>Description</B><BR>
<BR>
<TT>dynamic(Pred)</TT> specifies that the procedure whose
predicate indicator is <TT>Pred</TT> is a dynamic procedure. This directive
makes it possible to alter the definition of <TT>Pred</TT> by adding or
removing clauses. For more information refer to the section about dynamic
clause management (section&nbsp;<A HREF="gprolog030.html#Introduction:(Dynamic-clause-management)">7.7.1</A>).<BR>
<BR>
This directive shall precede the definition of <TT>Pred</TT> in the source
file.<BR>
<BR>
If there is no clause for <TT>Pred</TT> in the source file, <TT>Pred</TT>
exists however as an empty predicate (this means that
<TT>current_predicate(Pred)</TT> succeeds). <BR>
<BR>
In order to allow multiple definitions, <TT>Pred</TT> can also be a list of
predicate indicators or a sequence of predicate indicators using
<TT>','/2</TT> as separator.<BR>
<BR>
<B>Portability</B><BR>
<BR>
ISO directive.<BR>
<BR>
<A NAME="toc28"></A>
<H4 CLASS="subsubsection"><A NAME="htoc48">6.1.3</A>&nbsp;&nbsp;<TT>public/1</TT></H4>
<A NAME="public/1"></A>
 
<B>Templates</B>
<DL CLASS="list" COMPACT="compact"><DT CLASS="dt-list"><DD CLASS="dd-list"><TT>
public(+predicate_indicator)<BR>
public(+predicate_indicator_list)<BR>
public(+predicate_indicator_sequence)</TT></DL>
<B>Description</B><BR>
<BR>
<TT>public(Pred)</TT> specifies that the procedure whose predicate indicator
is <TT>Pred</TT> is a public procedure. This directive makes it possible to
inspect the clauses of <TT>Pred</TT>. For more information refer to the
section about dynamic clause management (section&nbsp;<A HREF="gprolog030.html#Introduction:(Dynamic-clause-management)">7.7.1</A>).<BR>
<BR>
This directive shall precede the definition of <TT>Pred</TT> in the source
file. Since a dynamic procedure is also public. It is useless (but correct)
to define a public directive for a predicate already declared as dynamic.<BR>
<BR>
In order to allow multiple definitions, <TT>Pred</TT> can also be a list of
predicate indicators or a sequence of predicate indicators using
<TT>','/2</TT> as separator.<BR>
<BR>
<B>Portability</B><BR>
<BR>
GNU Prolog directive. The ISO reference does not define any directive to
declare a predicate public but it does distinguish public predicates. It is
worth noting that in most Prolog systems the <TT>public/1</TT> directive is
as a visibility declaration. Indeed, declaring a predicate as public makes
it visible from any predicate defined in any other file (otherwise the
predicate is only visible from predicates defined in the same source file as
itself). When a module system is incorporated in GNU Prolog a more general
visibility declaration shall be provided conforming to the ISO reference.<BR>
<BR>
<A NAME="toc29"></A>
<H4 CLASS="subsubsection"><A NAME="htoc49">6.1.4</A>&nbsp;&nbsp;<TT>multifile/1</TT></H4>
 
<B>Templates</B>
<DL CLASS="list" COMPACT="compact"><DT CLASS="dt-list"><DD CLASS="dd-list"><TT>
multifile(+predicate_indicator)<BR>
multifile(+predicate_indicator_list)<BR>
multifile(+predicate_indicator_sequence)</TT></DL>
<B>Description</B><BR>
<BR>
<TT>multifile(Pred)</TT> is not supported by GNU Prolog.
When such a directive is encountered it is simply ignored. All clauses for a
given predicate must reside in a single file.<BR>
<BR>
<B>Portability</B><BR>
<BR>
ISO directive. Not supported.<BR>
<BR>
<A NAME="toc30"></A>
<H4 CLASS="subsubsection"><A NAME="htoc50">6.1.5</A>&nbsp;&nbsp;<TT>discontiguous/1</TT></H4>
 
<B>Templates</B>
<DL CLASS="list" COMPACT="compact"><DT CLASS="dt-list"><DD CLASS="dd-list"><TT>
discontiguous(+predicate_indicator)<BR>
discontiguous(+predicate_indicator_list)<BR>
discontiguous(+predicate_indicator_sequence)</TT></DL>
<B>Description</B><BR>
<BR>
<TT>discontiguous(Pred)</TT> specifies that the procedure whose predicate
indicator is <TT>Pred</TT> is a discontiguous procedure. Namely, the clauses
defining <TT>Pred</TT> are not restricted to be consecutive but can appear
anywhere in the source file.<BR>
<BR>
This directive shall precede the definition of <TT>Pred</TT> in the source
file.<BR>
<BR>
In order to allow multiple definitions, <TT>Pred</TT> can also be a list of
predicate indicators or a sequence of predicate indicators using
<TT>','/2</TT> as separator.<BR>
<BR>
<B>Portability</B><BR>
<BR>
ISO directive. The ISO reference document states that if there is no clause
for <TT>Pred</TT> in the source file, <TT>Pred</TT> exists however as an
empty predicate (i.e. <TT>current_predicate(Pred)</TT> will succeed). This
is not the case for GNU Prolog.<BR>
<BR>
<A NAME="toc31"></A>
<H4 CLASS="subsubsection"><A NAME="htoc51">6.1.6</A>&nbsp;&nbsp;<TT>ensure_linked/1</TT></H4>
 
<B>Templates</B>
<DL CLASS="list" COMPACT="compact"><DT CLASS="dt-list"><DD CLASS="dd-list"><TT>
ensure_linked(+predicate_indicator)<BR>
ensure_linked(+predicate_indicator_list)<BR>
ensure_linked(+predicate_indicator_sequence)</TT></DL>
<B>Description</B><BR>
<BR>
<TT>ensure_linked(Pred)</TT> specifies that the procedure
whose predicate indicator is <TT>Pred</TT> must be included by the linker.
This directive is useful when compiling to native code to force the linker to
include the code of a given predicate. Indeed, if the <TT>gplc</TT> is
invoked with an option to reduce the size of the executable
(section&nbsp;<A HREF="gprolog008.html#Using-the-compiler">3.4.3</A>), the linker only includes the code of predicates
that are statically referenced. However, the linker cannot detect dynamically
referenced predicates (used as data passed to a meta-call predicate). The use
of this directive prevents it to exclude the code of such predicates.<BR>
<BR>
In order to allow multiple definitions, <TT>Pred</TT> can also be a list of
predicate indicators or a sequence of predicate indicators using
<TT>','/2</TT> as separator.<BR>
<BR>
<B>Portability</B><BR>
<BR>
GNU Prolog directive.<BR>
<BR>
<A NAME="toc32"></A>
<H4 CLASS="subsubsection"><A NAME="htoc52">6.1.7</A>&nbsp;&nbsp;<TT>built_in/0</TT>,
 <TT>built_in/1</TT>,
 <TT>built_in_fd/0</TT>,
 <TT>built_in_fd/1</TT></H4>
 
 
 
 
<B>Templates</B>
<DL CLASS="list" COMPACT="compact"><DT CLASS="dt-list"><DD CLASS="dd-list"><TT>
built_in<BR>
built_in(+predicate_indicator)<BR>
built_in(+predicate_indicator_list)<BR>
built_in(+predicate_indicator_sequence)<BR>
built_in_fd<BR>
built_in_fd(+predicate_indicator)<BR>
built_in_fd(+predicate_indicator_list)<BR>
built_in_fd(+predicate_indicator_sequence)</TT></DL>
<B>Description</B><BR>
<BR>
<TT>built_in</TT> specifies that the procedures defined from
now have the <TT>built_in</TT> property (section&nbsp;<A HREF="gprolog031.html#predicate-property/2">7.8.2</A>).<BR>
<BR>
<TT>built_in(Pred)</TT> is similar to <TT>built_in/0</TT> but
only affects the procedure whose predicate indicator is <TT>Pred</TT>.<BR>
<BR>
This directive shall precede the definition of <TT>Pred</TT> in the source
file.<BR>
<BR>
In order to allow multiple definitions, <TT>Pred</TT> can also be a list of
predicate indicators or a sequence of predicate indicators using
<TT>','/2</TT> as separator.<BR>
<BR>
<TT>built_in_fd</TT> (resp.
<TT>built_in_fd(Pred)</TT>) is similar to
<TT>built_in</TT> (resp. <TT>built_in(Pred)</TT>) but sets the
<TT>built_in_fd</TT> predicate property (section&nbsp;<A HREF="gprolog031.html#predicate-property/2">7.8.2</A>).<BR>
<BR>
<B>Portability</B><BR>
<BR>
GNU Prolog directives.<BR>
<BR>
<A NAME="toc33"></A>
<H4 CLASS="subsubsection"><A NAME="htoc53">6.1.8</A>&nbsp;&nbsp;<TT>include/1</TT></H4>
 
<B>Templates</B>
<DL CLASS="list" COMPACT="compact"><DT CLASS="dt-list"><DD CLASS="dd-list"><TT>
include(+atom)</TT></DL>
<B>Description</B><BR>
<BR>
<TT>include(File)</TT> specifies that the content of the Prolog source
<TT>File</TT> shall be inserted. The resulting Prolog text is identical to
the Prolog text obtained by replacing the directive by the content of the
Prolog source <TT>File</TT>.<BR>
<BR>
See <TT>absolute_file_name/2</TT> for information about the syntax of
<TT>File</TT> (section&nbsp;<A HREF="gprolog049.html#absolute-file-name/2">7.26.1</A>).<BR>
<BR>
<B>Portability</B><BR>
<BR>
ISO directive.<BR>
<BR>
<A NAME="toc34"></A>
<H4 CLASS="subsubsection"><A NAME="htoc54">6.1.9</A>&nbsp;&nbsp;<TT>ensure_loaded/1</TT></H4>
 
<B>Templates</B>
<DL CLASS="list" COMPACT="compact"><DT CLASS="dt-list"><DD CLASS="dd-list"><TT>
ensure_loaded(+atom)</TT></DL>
<B>Description</B><BR>
<BR>
<TT>ensure_loaded(File)</TT> is not supported by GNU Prolog. When such a
directive is encountered it is simply ignored.<BR>
<BR>
<B>Portability</B><BR>
<BR>
ISO directive. Not supported.<BR>
<BR>
<A NAME="toc35"></A>
<H4 CLASS="subsubsection"><A NAME="htoc55">6.1.10</A>&nbsp;&nbsp;<TT>op/3</TT></H4>
<A NAME="op/3"></A>
 
<B>Templates</B>
<DL CLASS="list" COMPACT="compact"><DT CLASS="dt-list"><DD CLASS="dd-list"><TT>
op(+integer, +operator_specifier, +atom_or_atom_list)</TT></DL>
<B>Description</B><BR>
<BR>
<TT>op(Priority, OpSpecifier, Operator)</TT> alters the operator table. This
directive is executed as soon as it is encountered by calling the built-in
predicate <TT>op/3</TT> (section&nbsp;<A HREF="gprolog037.html#op/3:(Term-input/output)">7.14.10</A>). A system
directive is also generated to reflect the effect of this directive at
run-time (section&nbsp;<A HREF="gprolog008.html#Running-an-executable">3.4.4</A>).<BR>
<BR>
<B>Portability</B><BR>
<BR>
ISO directive.<BR>
<BR>
<A NAME="toc36"></A>
<H4 CLASS="subsubsection"><A NAME="htoc56">6.1.11</A>&nbsp;&nbsp;<TT>char_conversion/2</TT></H4>
 
<B>Templates</B>
<DL CLASS="list" COMPACT="compact"><DT CLASS="dt-list"><DD CLASS="dd-list"><TT>
char_conversion(+character, +character)</TT></DL>
<B>Description</B><BR>
<BR>
<TT>char_conversion(InChar, OutChar)</TT> alters the character-conversion
mapping. This directive is executed as soon as it is encountered by a call
to the built-in predicate <TT>char_conversion/2</TT>
(section&nbsp;<A HREF="gprolog037.html#char-conversion/2">7.14.12</A>). A system directive is also generated to reflect
the effect of this directive at run-time (section&nbsp;<A HREF="gprolog008.html#Running-an-executable">3.4.4</A>).<BR>
<BR>
<B>Portability</B><BR>
<BR>
ISO directive.<BR>
<BR>
<A NAME="toc37"></A>
<H4 CLASS="subsubsection"><A NAME="htoc57">6.1.12</A>&nbsp;&nbsp;<TT>set_prolog_flag/2</TT></H4>
 
<B>Templates</B>
<DL CLASS="list" COMPACT="compact"><DT CLASS="dt-list"><DD CLASS="dd-list"><TT>
set_prolog_flag(+flag, +term)</TT></DL>
<B>Description</B><BR>
<BR>
<TT>set_prolog_flag(Flag, Value)</TT> sets the value of the
Prolog flag <TT>Flag</TT> to <TT>Value</TT>. This directive is
executed as soon as it is encountered by a call to the built-in predicate
<TT>set_prolog_flag/2</TT> (section&nbsp;<A HREF="gprolog045.html#set-prolog-flag/2">7.22.1</A>). A system directive
is also generated to reflect the effect of this directive at run-time
(section&nbsp;<A HREF="gprolog008.html#Running-an-executable">3.4.4</A>).<BR>
<BR>
<B>Portability</B><BR>
<BR>
ISO directive.<BR>
<BR>
<A NAME="toc38"></A>
<H4 CLASS="subsubsection"><A NAME="htoc58">6.1.13</A>&nbsp;&nbsp;<TT>initialization/1</TT></H4>
<A NAME="initialization/1"></A>
 
<B>Templates</B>
<DL CLASS="list" COMPACT="compact"><DT CLASS="dt-list"><DD CLASS="dd-list"><TT>
initialization(+callable_term)</TT></DL>
<B>Description</B><BR>
<BR>
<TT>initialization(Goal)</TT> adds <TT>Goal</TT> to the set of goal which
shall be executed at run-time. A user directive is generated to execute
<TT>Goal</TT> at run-time. If several initialization directives appear in
the same file they are executed in the order of appearance
(section&nbsp;<A HREF="gprolog008.html#Running-an-executable">3.4.4</A>).<BR>
<BR>
<B>Portability</B><BR>
<BR>
ISO directive.<BR>
<BR>
<A NAME="toc39"></A>
<H4 CLASS="subsubsection"><A NAME="htoc59">6.1.14</A>&nbsp;&nbsp;<TT>foreign/2</TT>,
 <TT>foreign/1</TT></H4>
<A NAME="foreign/2"></A>
 
 
<B>Templates</B>
<DL CLASS="list" COMPACT="compact"><DT CLASS="dt-list"><DD CLASS="dd-list"><TT>
foreign(+callable_term, +foreign_option_list)<BR>
foreign(+callable_term)</TT></DL>
<B>Description</B><BR>
<BR>
<TT>foreign(Template, Options)</TT> defines an interface predicate whose
prototype is <TT>Template</TT> according to the options given by
<TT>Options</TT>. Refer to the foreign code interface for more information
(section&nbsp;<A HREF="gprolog066.html#Calling-C-from-Prolog">9.1</A>).<BR>
<BR>
<TT>foreign(Template)</TT> is equivalent to <TT>foreign(Template, [])</TT>.<BR>
<BR>
<B>Portability</B><BR>
<BR>
GNU Prolog directive.<BR>
<BR>

<HR SIZE=2>
Copyright (C) 1999-2007 Daniel Diaz
<BR>
<BR>
Verbatim copying and distribution of this entire article is permitted in any
medium, provided this notice is preserved. <BR>
<BR>
<A HREF="index.html#copyright">More about the copyright</A>
<HR>
<A HREF="gprolog020.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="gprolog022.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>