File: format-defs.tex

package info (click to toggle)
gprolog 1.2.9-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 5,492 kB
  • ctags: 4,818
  • sloc: ansic: 41,758; perl: 16,239; sh: 1,794; makefile: 1,032
file content (655 lines) | stat: -rw-r--r-- 16,050 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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
\newpage
\section{Format of definitions}
%HEVEA\cutdef[1]{subsection}
\subsection{General format}
The definition of control constructs, directives and built-in predicates is
presented as follows:

\Templates

Specifies the types of the arguments and which of them shall be instantiated
(mode). Types and modes are described later \RefSP{Types-and-modes}.

\Description

Describes the behavior (in the absence of any error conditions). It is
explicitly mentioned when a built-in predicate is re-executable on
backtracking. Predefined operators involved in the definition are also
mentioned.

\Errors

Details the error conditions. Possible errors are detailed later
\RefSP{Errors}.  For directives, this part is omitted.

\Portability

Specifies whether the definition conforms to the ISO standard or is a GNU Prolog
extension.

\subsection{Types and modes}
\label{Types-and-modes}
The templates part defines, for each argument of the concerned built-in
predicate, its mode and type. The mode specifies whether or not the argument
must be instantiated when the built-in predicate is called. The mode is
encoded with a symbol just before the type. Possible modes are:

\begin{itemize}

\item \texttt{+}: the argument must be instantiated.

\item \texttt{-}: the argument must be a variable (will be instantiated if
the built-in predicate succeeds).

\item \texttt{?}: the argument can be instantiated or a variable.

\end{itemize}

The type of an argument is defined by the following table:

\begin{tabular}{|l|p{11.5cm}|}
\hline

Type & Description \\

\hline\hline

\texttt{\Param{TYPE}\_list} & a list whose the type of each element is
\Param{TYPE} \\

\hline

\texttt{\Param{TYPE1}\_or\_\Param{TYPE2}} & a term whose type is either
\Param{TYPE1} or \Param{TYPE2} \\

\hline

\texttt{atom} & an atom \\

\hline

\texttt{atom\_property} & an atom property \RefSP{atom-property/2} \\

\hline

\texttt{boolean} & the atom \texttt{true} or \texttt{false} \\

\hline

\texttt{byte} & an integer $\geq$ 0 and $\leq$ 255 \\

\hline

\texttt{callable\_term} & an atom or a compound term \\

\hline

\texttt{character} & a single character atom \\

\hline

\texttt{character\_code} & an integer $\geq$ 1 and $\leq$ 255 \\

\hline

\texttt{clause} & a clause (fact or rule) \\

\hline

\texttt{close\_option} & a close option \RefSP{close/2} \\

\hline

\texttt{compound\_term} & a compound term \\

\hline

\texttt{evaluable} & an arithmetic expression \RefSP{Evaluation-of-an-arithmetic-expression} \\

\hline

\texttt{fd\_bool\_evaluable} & a boolean FD expression \RefSP{Boolean-FD-expressions} \\

\hline

\texttt{fd\_labeling\_option} & an FD labeling option \RefSP{fd-labeling/2}
\\

\hline

\texttt{fd\_evaluable} & an arithmetic FD expression \RefSP{FD-arithmetic-expressions} \\

\hline

\texttt{fd\_variable} & an FD variable \\

\hline

\texttt{flag} & a \Idx{Prolog flag} \RefSP{set-prolog-flag/2} \\

\hline

\texttt{float} & a floating point number \\

\hline

\texttt{head} & a head of a clause (atom or compound term) \\

\hline

\texttt{integer} & an integer \\

\hline

\texttt{in\_byte} & an integer $\geq$ 0 and $\leq$ 255 or \texttt{-1} (for
the end-of-file) \\

\hline

\texttt{in\_character} & a single character atom or the atom
\texttt{end\_of\_file} (for the end-of-file) \\

\hline

\texttt{in\_character\_code} & an integer $\geq$ 1 and $\leq$ 255 or
\texttt{-1} (for the end-of-file) \\

\hline

\texttt{io\_mode} & an atom in: \texttt{read}, \texttt{write} or
\texttt{append} \\

\hline

\texttt{list} & the empty list \texttt{[]} or a non-empty list
\texttt{[\_|\_]} \\

\hline

\texttt{nonvar} & any term that is not a variable \\

\hline

\texttt{number} & an integer or a floating point number \\

\hline

\texttt{operator\_specifier} & an operator specifier \RefSP{op/3:(Term-input/output)} \\

\hline

\texttt{os\_file\_property} & an operating system file property \RefSP{file-property/2}
\\

\hline

\texttt{predicate\_indicator} & a term \texttt{Name/Arity} where
\texttt{Name} is an atom and \texttt{Arity} an integer $\geq$ 0. A callable
term can be given if the \IdxPF{strict\_iso} \Idx{Prolog flag} is switched
off \RefSP{set-prolog-flag/2} \\
\hline

\texttt{predicate\_property} & a predicate property
\RefSP{predicate-property/2} \\

\hline

\texttt{read\_option} & a read option \RefSP{read-term/3} \\

\hline

\texttt{socket\_address} & a term of the form \texttt{'AF\_UNIX'(A)} or
\texttt{'AF\_INET'(A,N)} where \texttt{A} is an atom and \texttt{N} an
integer \\

\hline

\texttt{socket\_domain} & an atom in: \texttt{'AF\_UNIX'} or
\texttt{'AF\_INET'} \\

\hline

\texttt{source\_sink} & an atom identifying a source or a sink \\

\hline

\texttt{stream} & a stream-term: a term of the form \texttt{'\$stream'(N)}
where \texttt{N} is an integer $\geq$ 0 \\

\hline

\texttt{stream\_option} & a stream option \RefSP{open/4} \\

\hline

\texttt{stream\_or\_alias} & a stream-term or an alias (atom) \\

\hline

\texttt{stream\_position} & a stream position: a term
\texttt{'\$stream\_position'(I1, I2, I3, I4)} where
\texttt{I1}, \texttt{I2}, \texttt{I3} and \texttt{I4} are integers \\

\hline

\texttt{stream\_property} & a stream property \RefSP{stream-property/2} \\

\hline

\texttt{stream\_seek\_method} & an atom in: \texttt{bof}, \texttt{current}
or \texttt{eof} \\

\hline

\texttt{term} & any term \\

\hline

\texttt{var\_binding\_option} & a variable binding option
\RefSP{bind-variables/2} \\

\hline

\texttt{write\_option} & a write option \RefSP{write-term/3} \\

\hline
\end{tabular}

\subsection{Errors}
\label{Errors}

\subsubsection{General format and error context}
\label{General-format-and-error-context}
When an error occurs an exception of the form:
\texttt{error(\Param{ErrorTerm}, \Param{Caller})} is raised.
\Param{ErrorTerm} is a term specifying the error (detailed in next
sections) and \Param{Caller} is a term specifying the context of
the error. The context is either the predicate indicator of the last invoked
built-in predicate or an atom giving general context information.

Using exceptions allows the user both to recover an error using
\IdxPB{catch/3} \RefSP{catch/3} and to raise an error using
\IdxPB{throw/1} \RefSP{catch/3}. 

To illustrate how to write a error cases, let us write a predicate
\texttt{my\_pred(X)} where \texttt{X} must be an integer:

\begin{Indentation}
\begin{verbatim}
my_pred(X) :-
        (   nonvar(X) ->
            true
        ;   throw(error(instantiation_error), my_pred/1)),
        ),
        (   integer(X) ->
            true
        ;   throw(error(type_error(integer, X), my_pred/1))
        ),
        ...
\end{verbatim}
\end{Indentation}

To help the user to write these error cases, a set of system predicates is
provided to raise errors. These predicates are of the form
\texttt{'\$pl\_err\_...'} and they all refer to the implicit error context.
The predicates \IdxPB{set\_bip\_name/2} \RefSP{set-bip-name/2} and
\IdxPB{current\_bip\_name/2} \RefSP{current-bip-name/2} are provided to
set and recover the name and the arity associated to this context (an arity
$<$ 0 means that only the atom corresponding to the functor is significant).
Using these system predicates the user could define the above predicate as
follow:

\begin{Indentation}
\begin{verbatim}
my_pred(X) :-
        set_bip_name(my_pred,1),
        (   nonvar(X) ->
            true
        ;   '$pl_err_instantiation'
        ),
        (   integer(X) ->
            true
        ;   '$pl_err_type'(integer, X)
        ),
        ...
\end{verbatim}
\end{Indentation}

The following sections detail each kind of errors (and associated system
predicates).

\subsubsection{Instantiation error}
\label{Instantiation-error}
An instantiation error occurs when an argument or one of its components is
variable while an instantiated argument was expected.
\Param{ErrorTerm} has the following form:
\texttt{instantiation\_error}.

The system predicate \texttt{'\$pl\_err\_instantiation'} raises this
error in the current error context \RefSP{General-format-and-error-context}.

\subsubsection{Type error}
\label{Type-error}
A type error occurs when the type of an argument or one of its components is
not the expected type (but not a variable). \Param{ErrorTerm} has
the following form: \texttt{type\_error(\Param{Type}, Culprit)} where
\Param{Type} is the expected type and \Param{Culprit}
the argument which caused the error. \Param{Type} is one of:

\begin{ItemizeThreeCols}

\item \texttt{atom}

\item \texttt{atomic}

\item \texttt{boolean}

\item \texttt{byte}

\item \texttt{callable}

\item \texttt{character}

\item \texttt{compound}

\item \texttt{evaluable}

\item \texttt{fd\_bool\_evaluable}

\item \texttt{fd\_evaluable}

\item \texttt{fd\_variable}

\item \texttt{float}

\item \texttt{in\_byte}

\item \texttt{in\_character}

\item \texttt{integer}

\item \texttt{list}

\item \texttt{number}

\item \texttt{predicate\_indicator}

\item \texttt{variable}

\end{ItemizeThreeCols}

The system predicate \texttt{'\$pl\_err\_type'(Type, Culprit)} raises this
error in the current error context \RefSP{General-format-and-error-context}.

\subsubsection{Domain error}
\label{Domain-error}
A domain error occurs when the type of an argument is correct but its value
is outside the expected domain. \Param{ErrorTerm} has the
following form: \texttt{domain\_error(\Param{Domain}, \Param{Culprit})}
where \Param{Domain} is the expected domain and
\Param{Culprit} the argument which caused the error.
\Param{Domain} is one of:

\begin{ItemizeThreeCols}

\item \texttt{atom\_property}

\item \texttt{buffering\_mode}

\item \texttt{character\_code\_list}

\item \texttt{close\_option}

\item \texttt{date\_time}

\item \texttt{eof\_action}

\item \texttt{fd\_labeling\_option}

\item \texttt{flag\_value}

\item \texttt{format\_control\_sequence}

\item \texttt{g\_array\_index}

\item \texttt{io\_mode}

\item \texttt{non\_empty\_list}

\item \texttt{not\_less\_than\_zero}

\item \texttt{operator\_priority}

\item \texttt{operator\_specifier}

\item \texttt{os\_file\_permission}

\item \texttt{os\_file\_property}

\item \texttt{os\_path}

\item \texttt{predicate\_property}

\item \texttt{prolog\_flag}

\item \texttt{read\_option}

\item \texttt{selectable\_item}

\item \texttt{socket\_address}

\item \texttt{socket\_domain}

\item \texttt{source\_sink}

\item \texttt{statistics\_key}

\item \texttt{statistics\_value}

\item \texttt{stream}

\item \texttt{stream\_option}

\item \texttt{stream\_or\_alias}

\item \texttt{stream\_position}

\item \texttt{stream\_property}

\item \texttt{stream\_seek\_method}

\item \texttt{stream\_type}

\item \texttt{term\_stream\_or\_alias}

\item \texttt{var\_binding\_option}

\item \texttt{write\_option}

\end{ItemizeThreeCols}

The system predicate \texttt{'\$pl\_err\_domain'(Domain, Culprit)} raises
this error in the current error context \RefSP{General-format-and-error-context}.

\subsubsection{Existence error}
\label{Existence-error}
an existence error occurs when an object on which an operation is to be
performed does not exist. \Param{ErrorTerm} has the following
form: \texttt{existence\_error(\Param{Object}, \Param{Culprit})} where
\Param{Object} is the type of the object and
\Param{Culprit} the argument which caused the error.
\Param{Object} is one of:

\begin{ItemizeThreeCols}

\item \texttt{procedure}

\item \texttt{source\_sink}

\item \texttt{stream}

\end{ItemizeThreeCols}

The system predicate \texttt{'\$pl\_err\_existence'(Object, Culprit)} raises
this error in the current error context \RefSP{General-format-and-error-context}.

\subsubsection{Permission error}
\label{Permission-error}
A permission error occurs when an attempt to perform a prohibited operation
is made. \Param{ErrorTerm} has the following form:
\texttt{permission\_error(\Param{Operation}, \Param{Permission},
\Param{Culprit})} where \Param{Operation} is the operation which
caused the error, \Param{Permission} the type of the tried
permission and \Param{Culprit} the argument which caused the
error. \Param{Operation} is one of:

\begin{ItemizeThreeCols}

\item \texttt{access}

\item \texttt{add\_alias}

\item \texttt{close}

\item \texttt{create}

\item \texttt{input}

\item \texttt{modify}

\item \texttt{open}

\item \texttt{output}

\item \texttt{reposition}

\end{ItemizeThreeCols}

and \Param{Permission} is one of:

\begin{ItemizeThreeCols}

\item \texttt{binary\_stream}

\item \texttt{flag}

\item \texttt{operator}

\item \texttt{past\_end\_of\_stream}

\item \texttt{private\_procedure}

\item \texttt{source\_sink}

\item \texttt{static\_procedure}

\item \texttt{stream}

\item \texttt{text\_stream}

\end{ItemizeThreeCols}

The system predicate \texttt{'\$pl\_err\_permission'(Operation, Permission,
Culprit)} raises this error in the current error context \RefSP{General-format-and-error-context}.

\subsubsection{Representation error}
\label{Representation-error}
A representation error occurs when an implementation limit has been
breached. \Param{ErrorTerm} has the following form:
\texttt{representation\_error(\Param{Limit})} where \Param{Limit}
is the name of the reached limit. \Param{Limit} is one of:

\begin{ItemizeThreeCols}

\item \texttt{character}

\item \texttt{character\_code}

\item \texttt{in\_character\_code}

\item \texttt{max\_arity}

\item \texttt{max\_integer}

\item \texttt{min\_integer}

\item \texttt{too\_many\_variables}

\end{ItemizeThreeCols}

The errors \texttt{max\_integer} and \texttt{min\_integer} are not currently
implemented.

The system predicate \texttt{'\$pl\_err\_representation'(Limit)} raises this 
error in the current error context \RefSP{General-format-and-error-context}.

\subsubsection{Evaluation error}
\label{Evaluation-error}
An evaluation error occurs when an arithmetic expression gives rise to
an exceptional value. \Param{ErrorTerm} has the following form:
\texttt{evaluation\_error(\Param{Error})} where \Param{Error} is
the name of the error. \Param{Error} is one of:

\begin{ItemizeThreeCols}

\item \texttt{float\_overflow}

\item \texttt{int\_overflow}

\item \texttt{undefined}

\item \texttt{underflow}

\item \texttt{zero\_divisor}

\end{ItemizeThreeCols}

The errors \texttt{float\_overflow}, \texttt{int\_overflow},
\texttt{undefined} and \texttt{underflow} are not currently
implemented.

The system predicate \texttt{'\$pl\_err\_evaluation'(Error)} raises this
error in the current error context \RefSP{General-format-and-error-context}.

\subsubsection{Resource error}
\label{Resource-error}
A resource error occurs when GNU Prolog does not have enough resources.
\Param{ErrorTerm} has the following form:
\texttt{resource\_error(\Param{Resource})} where \Param{Resource} is the
name of the resource. \Param{Resource} is one of:

\begin{ItemizeThreeCols}

\item \texttt{print\_object\_not\_linked}

\item \texttt{too\_big\_fd\_constraint}

\item \texttt{too\_many\_open\_streams}

\end{ItemizeThreeCols}

The system predicate \texttt{'\$pl\_err\_resource'(Resource)} raises this
error in the current error context \RefSP{General-format-and-error-context}.

\subsubsection{Syntax error}
\label{Syntax-error}
A syntax error occurs when a sequence of character does not conform to the
syntax of terms. \Param{ErrorTerm} has the following form:
\texttt{syntax\_error(\Param{Error})} where \Param{Error} is an
atom explaining the error.

The system predicate \texttt{'\$pl\_err\_syntax'(Error)} raises this
error in the current error context \RefSP{General-format-and-error-context}.

\subsubsection{System error}
A system error can occur at any stage. A system error is generally
associated to an external component (e.g. operating system).
\Param{ErrorTerm} has the following form:
\texttt{system\_error(\Param{Error})} where \Param{Error} is an
atom explaining the error. This is an extension to ISO which only defines
\texttt{system\_error} without arguments.

The system predicate \texttt{'\$pl\_err\_system'(Error)} raises this
error in the current error context \RefSP{General-format-and-error-context}.

%HEVEA\cutend