-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jalog_quick_reference.html
838 lines (761 loc) · 34.1 KB
/
Jalog_quick_reference.html
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
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
<!DOCTYPE html>
<head>
<title>Jalog Quick Reference</title>
<style>
table {
border-collapse: collapse;
border: 1px solid black;
}
th, td {
padding: 5px;
text-align: left;
}
dd code {
font-size: 15px;
}
dd pre {
font-size: 15px;
}
dt code {
font-size: 18px;
}
</style>
</head>
<body>
<p ALIGN="right"><EM>
<b>Jalog 1.5</b></EM>
</p>
<HR>
<h1>Jalog Quick Reference</h1>
<h2>Built-in Predicates</h2>
<dl>
<dt><font size="+1"><b><code>assert(</code><i>Fact</i><code>)</code></b></font></dt>
<dd><p>Stores the fact <i>Fact</i> to the end of the database. Same as <code>assertz</code>.</p>
<p>Example:</p>
<p><code>assert(connection(7588, 9032))</code></p>
</dd>
<dt><font size="+1"><b><code>asserta(</code><i>Fact</i><code>)</code></b></font></dt>
<dd><p>Stores the fact <i>Fact</i> to the beginning of the database.</p>
<p>Example:</p>
<p><code>asserta(address("Sqrt", $082A))</code></p>
</dd>
<dt><font size="+1"><b><code>assertz(</code><i>Fact</i><code>)</code></b></font></dt>
<dd><p>Stores the fact <i>Fact</i> to the end of the database.</p>
<p>Example:</p>
<p><code>assertz(connection(7588, 9032))</code></p>
</dd>
<dt><font size="+1"><b><code>bound(</code><i>Var</i><code>)</code></b></font></dt>
<dd>
<p>Succeeds, if the parameter <i>Var</i> is bound, otherwise fails.</p>
</dd>
<!-- 1.5 -->
<dt><font size="+1"><b><code>closefile(</code><i>SymbolicFileName</i><code>)</code></b></font></dt>
<dd><p>Closes the named file. <code>closefile</code> succeeds even if the file has not been opened.</p>
<p>Example:</p>
<p><code>closefile(report)</code></p>
</dd>
<dt><font size="+1"><b><code>comline_arg(</code><i>Number</i><code>,
</code><i>Option</i><code>, </code><i>Argument</i><code>)</code></b></font></dt>
<dd>
<p> <i>Not implemented like other built-in
predicates. Instead, each command line argument is stored to the
database as a separate fact.</i> </p>
<p>Returns information about one command line argument, if one can
be found.</p>
<p>A command line example:</p>
<code>> java -jar jalog.jar myprogram.pro -foo=bar -up report.txt</code>
<p> <i><b>Note</b> the equal sign separating an option and its argument.</i></p>
<p>Parameters of this command line are stored to the database prior to starting
<code>myprogram.pro</code> as following facts:</p>
<pre>
comline_arg(1, "foo", "bar").
comline_arg(2, "up", "").
comline_arg(3, "", "report.txt").</pre>
</dd>
<dt><font size="+1"><b><code>concat(</code><i>String1</i><code>, </code><i>String2</i><code>, </code><i>LongString</i><code>)</code></b></font></dt>
<dd><p>Obtains <i>LongString</i> by concatenating <i>String1</i> and <i>String2</i></p>
<p>Example:</p>
<p><code>concat(S, ".pro", Filename)</code></p>
</dd>
<!-- 1.5 updated -->
<dt><font size="+1"><b><code>consult(</code><i>Filename</i><code>)</code></b></font></dt>
<dd>
<p>Reads the rules and facts to the database and executes the goals from the file <a href="#filename"
><i>Filename</i></a>.</p>
<p>If <i>Filename</i> does not specify full path, then the consult directory
is used. Initially the consult directory is the directory containing
the main program. The consult directory can be changed by the <code>consult_dir</code>
predicate.</p>
<p>Example:</p>
<p><code>consult("game_library.pro")</code></p>
<p>The predicate name <code>consult</code> in another name of the predicate <code>include</code>.</p>
</dd>
<!-- 1.5 updated -->
<dt><font size="+1"><b><code>consult_data(</code><i>Filename</i><code>, </code><i>DatabaseName</i><code>)</code></b></font></dt>
<dt><font size="+1"><b><code>consult_data(</code><i>Filename</i><code>, </code><i>Filter</i><code>)</code></b></font></dt>
<dd>
<p>Reads the facts from the <a href="#filename"><i>Filename</i></a> to the end of the database.</p>
<p>If the second parameter is a symbol it is interpreted as a database name. In this case only facts that belong to this database is read.</p>
<p>If the second parameter is a list of strings it is interpreted as a filter.
Each string of the filter must contain a predicate indicator in form <i>name</i>/<i>arity</i> .
In this case only facts specified in the <code>Filter</code> are read.</p>
<p>Examples:</p>
<p><code>consult_data("samples.dat", samples)</code></p>
<p><code>consult_data("data.dat", ["cars/4", "houses/2"])</code></p>
</dd>
<!-- 1.5 updated -->
<dt><font size="+1"><b><code>consult_dir(</code><i>ConsultDirname</i><code>)</code></b></font></dt>
<dd>
<p>The current consult directory is used by the <code>consult</code>
predicate to locate files when no full path is specified. It is not used
by <code>consult_data</code> or any other predicate.</p>
<p>If <a href="#ConsultDirname"
><i>ConsultDirname</i></a> is bound to a string sets current consult directory.</p>
<p>If <i>ConsultDirname</i> is open it will be bound to the current
consult directory name. The directory name is absolute and always begins with
"<code>file:</code>" or "<code>res:</code>". It can be used as an argument to
<code>set_consult_dir</code> .</p>
<p>Examples:</p>
<p><CODE>"file:C:/data"</CODE> - refers to the data directory at the root of
the C disk.</p>
<p><CODE>"res:lib/routes"</CODE> - refers to a resource directory.</p>
<p><CODE>"sub"</CODE> - refers to the subdirectory <code>sub</code> of
the current directory.</p>
</dd>
<!-- 1.5 -->
<dt><font size="+1"><b><code>deletefile(</code><i>FileName</i><code>)</code></b></font></dt>
<dd><p>Deletes the file <i>FileName</i>.</p>
<p>Example:</p>
<p><code>deletefile("temp.dat")</code></p>
</dd>
<!-- 1.5 updated -->
<dt><font size="+1"><b><code>dynamic(</code><i>PredicateIndicator</i><code>)</code></b></font></dt>
<dt><font size="+1"><b><code>dynamic(</code><i>PredicateIndicator</i><code>, </code><i>DatabaseName</i><code>)</code></b></font></dt>
<dd>
<p>Prevents an error message, if no clause matching PredicateIndicator
is found in the database. This is intended for predicates that can
be asserted and retracted in runtime. This is intended to be used
as a directive.</p>
<p>A <i>PredicateIndicator</i> must be a string of form
<i>Functor</i><code>/</code><i>Arity</i> .
</p>
<p>A <i>DatabaseName</i>, if present, specifies in which database these
facts are stored. If absent default database <code>dbasedom</code> is
used.
</p>
<p>Examples:</p>
<p><code>:- dynamic("route/3").</code></p>
<p><code>:- dynamic("path/3", paths).</code></p>
</dd>
<!-- 1.5 -->
<dt><font size="+1"><b><code>existfile(</code><i>FileName</i><code>)</code></b></font></dt>
<dd><p>Succeeds if the file <i>FileName</i> exists.</p>
<p>Example:</p>
<p><code>existfile("motor/params.txt")</code></p>
</dd>
<dt id="exit"><font size="+1"><b><code>exit</code></b></font></dt>
<dd>
<p>Terminates the program with exit code <code>0</code>.</p>
<p>However, if exit is called (typically very indirectly) in
execution of the first argument of <code>trap</code> then control
is transferred to the <a href="#trap"><code>trap</code></a> predicate.</p>
</dd>
<dt><font size="+1"><b><code>exit(</code><i>Int_value</i><code>)</code></b></font></dt>
<dd>
<p>Terminates the program with exit code <i>Int_value</i>.</p>
<p>However, if exit is called (typically very indirectly) in
execution of the first argument of <code>trap</code> then control
is transferred to the <a href="#trap"><code>trap</code></a> predicate.</p>
</dd>
<dt><font size="+1"><b><code>fail</code></b></font></dt>
<dd>
<p>This call fails always.</p>
</dd>
<!-- 1.5 -->
<dt><font size="+1"><b><code>file_str(</code><i>FileName</i><code>, </code><i>StringVariable</i><code>)</code></b></font></dt>
<dd><p>The contents of </code><i>FileName</i> is read into <i>StringVariable</i>.
The file must be an ASCII or UTF-8 coded text file.</p>
<p>Example:</p>
<p><code>file_str("data.dat", String1)</code></p>
</dd>
<dt><font size="+1"><b><code>findall(</code><i>Variable</i><code>, </code><i>Atom</i><code>, </code><i>ListVariable</i><code>)</code></b></font></dt>
<dd><p>Collects the values from backtracking into a list. Thus, if <i>Atom</i> is a predicate with its arguments represented by valid variable names, and <i>Variable</i> is the name of one of the variables in the predicate, <i>ListVariable</i> will be bound to the list of values for that variable that was obtained from instances when the predicate can succeed due to backtracking.</p>
<p>Example:</p>
<p><code>findall(P, substring("a, b, c, d", P, _, ","), L) </code><br/>
<code>L</code> will contain the positions of commas:
<code>[2, 5, 8]</code></p>
</dd>
<dt><font size="+1"><b><code>foreach_(</code><i>Var</i><code>, </code><i>List</i><code>)</code></b></font></dt>
<dd>
<p>Binds the first variable <i>Var</i> in the first call to
the first item of the list <i>List</i> in the second variable, and in recalls
to the succeeding items.</p>
<p><code>foreach_(X, [1, 2, 3]), write(' ', X), fail.</code> prints
<code> 1 2 3</code></p>
</dd>
<dt><font size="+1"><b><code>free(</code><i>Var</i><code>)</code></b></font></dt>
<dd>
<p>Succeeds, if the parameter <i>Var</i> is open, otherwise fails.</p>
</dd>
<dt><font size="+1"><b><code>frontchar(</code><i>String</i><code>, </code><i>FrontChar</i><code>, </code><i>RestString</i><code>)</code></b></font></dt>
<dd><p>Isolates the first character of <i>String</i>.</p>
</dd>
<dt><font size="+1"><b><code>frontstr(</code><i>NumberOfChars</i><code>, </code><i>String1</i><code>, </code><i>StartStr</i><code>, </code><i>String2</i><code>)</code></b></font></dt>
<dd><p>Splits <i>String1</i> into two parts. <i>StartStr</i> will contain the first <i>NumberOfChars</i> characters in <i>String1</i> and <i>String2</i> will contain the rest.</p>
</dd>
<dt><font size="+1"><b><code>fronttoken(</code><i>String</i><code>, </code><i>Token</i><code>, </code><i>RestString</i><code>)</code></b></font></dt>
<dd><p>Isolates the first <a href="Jalog_language_reference.html#tokens">token</a> of <i>String</i>. <a href="Jalog_language_reference.html#whitespace">Whitespace</a> in front of the token is skipped.</p>
</dd>
<!-- 1.5 -->
<dt><font size="+1"><b><code>include(</code><i>Filename</i><code>)</code></b></font></dt>
<dd>
<p>Reads the rules and facts to the database and executes the goals from the file <a href="#filename"
><i>Filename</i></a>.</p>
<p>If <i>Filename</i> does not specify full path, then the consult directory
is used. Initially the consult directory is the directory containing
the main program. The consult directory can be changed by the <code>consult_dir</code>
predicate.</p>
<p>Example:</p>
<p><code>include("game_library.pro")</code></p>
</dd>
<dt><font size="+1"><b><code>is_char(</code><i>Var</i><code>)</code></b></font></dt>
<dd>
<p>Succeeds, if the parameter <i>Var</i> is bound to a character value.</p>
</dd>
<dt><font size="+1"><b><code>is_compound(</code><i>Var</i><code>)</code></b></font></dt>
<dd>
<p>Succeeds, if the parameter <i>Var</i> is bound to a compound structure.</p>
</dd>
<dt><font size="+1"><b><code>is_integer(</code><i>Var</i><code>)</code></b></font></dt>
<dd>
<p>Succeeds, if the parameter <i>Var</i> is bound to an integer value.</p>
</dd>
<dt><font size="+1"><b><code>is_list(</code><i>Var</i><code>)</code></b></font></dt>
<dd>
<p>Succeeds, if the parameter <i>Var</i> is bound to a list structure.</p>
</dd>
<dt><font size="+1"><b><code>is_real(</code><i>Var</i><code>)</code></b></font></dt>
<dd>
<p>Succeeds, if the parameter <i>Var</i> is bound to a real value.</p>
</dd>
<dt><font size="+1"><b><code>is_string(</code><i>Var</i><code>)</code></b></font></dt>
<dd>
<p>Succeeds, if the parameter <i>Var</i> is bound to a string value.</p>
</dd>
<dt><font size="+1"><b><code>isname(</code><i>StringParam</i><code>)</code></b></font></dt>
<dd>
<p>Succeeds, if <i>StringParam</i> is a name.</p>
</dd>
<dt><font size="+1"><b><code>member(</code><i>Elem</i><code>, </code><i>List</i><code>)</code></b></font></dt>
<dd><p>If <code>Elem</code> is bound, succeeds if <code>Elem</code>is a member of <code>List</code>. If <code>Elem</code> is free, picks one element of <code>List</code> and on backtracking next elements one by one, and fails at the end of <code>List</code>. </p>
</dd>
<dt><font size="+1"><b><code>nl</code></b></font></dt>
<dd>
<p>Prints a newline character.</p>
</dd>
<dt><font size="+1"><b><code>not(</code><i>Predicate_call</i><code>)</code></b></font></dt>
<dd>
<p>Fails, if <i>Predicate_call</i> succeeds, succeeds, if <i>Predicate_call
</i> fails.</p>
<p>Example:</p>
<p><code>not(connection(7588, 9032))</code> fails, if <code>
connection(7588, 9032)</code> is found from the database, otherwise
succeeds.</p>
</dd>
<!-- 1.5 -->
<dt><font size="+1"><b><code>openappend(</code><i>SymbolicFileName</i><code>, </code><i>FileName</i><code>)</code></b></font></dt>
<dd><p>Opens the disk file <i>FileName</i> for appending and attaches the symbolic <i>FileName</i> to that file.
<i>SymbolicFileName</i> cannot be <code>screen</code>. The <i>FileName</i> must not begin with <code>res:</code> .
<p>Example:</p>
<p><code>openappend(datafile, "data.dat")</code></p>
</dd>
<!-- 1.5 -->
<dt><font size="+1"><b><code>openread(</code><i>SymbolicFileName</i><code>, </code><i>FileName</i><code>)</code></b></font></dt>
<dd><p>Opens the disk file <i>FileName</i> for reading and attaches the <i>SymbolicFileName</i> to that file.
<i>SymbolicFileName</i> cannot be <code>keyboard</code>.
<p>Example:</p>
<p><code>openead(parameters, "motor/params.txt")</code></p>
</dd>
<!-- 1.5 -->
<dt><font size="+1"><b><code>openwrite(</code><i>SymbolicFileName</i><code>, </code><i>FileName</i><code>)</code></b></font></dt>
<dd><p>Opens the disk file <i>FileName</i> for writing and attaches the symbolic <i>FileName</i> to that file.
If the file <i>FileName</i> alredy exists on the disk, it is deleted. <i>SymbolicFileName</i> cannot be <code>screen</code>. The <i>FileName</i> must not begin with <code>res:</code> .
<p>Example:</p>
<p><code>openwrite(report, "summary.txt")</code></p>
</dd>
<!-- 1.5 -->
<dt><font size="+1"><b><code>readdevice(</code><i>SymbolicFileName</i><code>)</code></b></font></dt>
<dd><p>If <i>SymbolicFileName</i> is bound, then reassigns the current read device to the file opened with the given <i>SymbolicFileName</i>. If the symbol is <code>keyboard</code>, then assigns the current read device to the standard input.</p>
<p>If <i>SymbolicFileName</i> is free, then binds <i>SymbolicFileName</i> to the current read device.</p>
<p>Example:</p>
<p><code>readdevice(Temp),</code></p>
<p><code>readdevice(parameters),</code></p>
</dd>
<!-- 1.5 -->
<dt><font size="+1"><b><code>readln(</code><i>StringVariable</i><code>)</code></b></font></dt>
<dd>
<p>Reads the characters from the current read device (the <code>keyboard</code> until the devce is changed with <code>readdevice</code>) to the <i>StringVariable</i> until the end of the line</p>
<p>Example:</p>
<p><code>readln(Line)</code></p>
</dd>
<dt id="retract"><font size="+1"><b><code>retract(</code><i>Fact</i><code>)</code></b></font></dt>
<dd>
<p>Deletes the first fact in the database that matches the given <i>Fact</i>. The argument cannot be open. It must be a compound that can have open arguments.
<p>Example:</p>
<pre>retract(route("Moscow", _))
</pre>
</dd>
<dt id="retractall"><font size="+1"><b><code>retractall(</code><i>Fact</i><code>)</code></b></font></dt>
<dd>
<p>Deletes all facts in the database that match the given <i>Fact</i>. The argument cannot be open. It must be a compound that can have open arguments.
<p>Example:</p>
<pre>retractall(route("Moscow", _))
</pre>
</dd>
<!-- 1.5 -->
<dt><font size="+1"><b><code>save(</code><i>FileName</i><code>)</code></b></font></dt>
<dt><font size="+1"><b><code>save(</code><i>FileName</i><code>, </code><i>DatabaseName</i><code>)</code></b></font></dt>
<dd><p>Saves all facts of a given database to a file <i>FileName</i>. If <code>save</code> is called with only one argument (no <i>DatabaseName</i>) it will save facts of the default <code>dbasedom</code> database to the file <i>FileName</i>. If <code>save</code> is called with two arguments (<i>FileName</i> and <i>DatabaseName</i>), it will save facts of the <i>DatabaseName</i> to the file <i>FileName</i>.</p>
<p>Example:</p>
<p><code>save("main_data.dat"), % </code>all facts of <code>dbasedom</code>.</p>
<p><code>save("settings.dat", settings), % </code>all facts of <code>settings</code>.</p>
</dd>
<dt id="searchchar"><font size="+1"><b><code>searchchar(</code><i>Text</i><code>, </code>
<i>Character</i><code>, </code><i>Position</i><code>)</code></b></font></dt>
<dd>
<p>Searches <i>Character</i> in <i>Text</i>. The first call finds the first <i>Position</i>. Each recall finds the next <i>Position</i> as long as there are any. Fails when no more found.
</p>
<p>Example:</p>
<p>
<code>searchchar("A-B+C-D", '-', P).</code><br/>
Returns <code>P</code> = 2 on first call. If backtracked returns <code>P</code> = 6. If backtracked again fails.
</p>
</dd>
<dt id="searchstring"><font size="+1"><b><code>searchstring(</code><i>Text</i><code>, </code>
<i>String</i><code>, </code><i>Position</i><code>)</code></b></font></dt>
<dd>
<p>Searches <i>String</i> in <i>Text</i>. The first call finds the first <i>Position</i>. Each recall finds the next <i>Position</i> as long as there are any. Fails when no more found.
</p>
<p>Example:</p>
<p>
<code>searchstring("Apple,, Banana, Orange", ",,", P).</code><br/>
Returns <code>P</code> = 6 on first call. If backtracked fails.
</p>
</dd>
<dt id="str_char"><font size="+1"><b><code>str_char(</code><i>StringParam</i><code>, </code>
<i>CharParam</i><code>)</code></b></font></dt>
<dd>
<p>One of the parameters must be bound. Converts the bound parameter to other type. If both parameters are bound succeeds if both parameters are equivalent.</p>
<p>Example:</p>
<p><code>str_char("A", 'A').</code><br/>Succeeds
</p>
</dd>
<dt id="str_int"><font size="+1"><b><code>str_int(</code><i>StringParam</i><code>, </code>
<i>IntParam</i><code>)</code></b></font></dt>
<dd>
<p>One of the parameters must be bound. If <i>StringParam</i> is bound it must be a decimal integer (possibly preceded by a minus sign).
Converts the bound parameter to other type. If both parameters are bound succeeds if both parameters are equivalent.</p>
<p>Example:</p>
<p><code>str_int("-32768", -32768).</code><br/>Succeeds
</p>
</dd>
<dt id="str_len"><font size="+1"><b><code>str_len(</code><i>String</i><code>, </code>
<i>Length</i><code>)</code></b></font></dt>
<dd>
<p><i>Length</i> is set to number of characters in the <i>String</i>.</p>
<p>Example:</p>
<p>
<code>str_len("Very long string", Len).</code><br/>
Sets <code>Len</code> to 16.
</p>
</dd>
<!-- 1.5 -->
<dt><font size="+1"><b><code>subchar(</code><i>String</i><code>, </code><i>Position</i><code>, </code><i>Char</i><code>)</code></b></font></dt>
<dd><p><code>subchar</code> returns the character at a given position in a string. The first character has position 1.</p>
<p>Example:</p>
<p><code>subchar("ABC", 2, Char) % Char </code> is bound to <code>'B'</code>.</p>
</dd>
<dt id="substring"><font size="+1"><b><code>substring(</code><i>LongString</i><code>, </code>
<i>Pos</i><code>, </code><i>Len</i><code>, </code><i>SubString</i><code>)</code></b></font></dt>
<dd>
<p>The parameter <i>LongString</i> must be bound to a string.</p>
<p>If <i>Pos</i> and <i>Len</i> are bound then <i>Substring</i> is bound to part of <i>LongString</i> that starts at <i>Pos</i> and is <i>Len</i> characters long.</p>
<p>if <i>Pos</i> is bound and <i>Substring</i> is bound and <i>Len</i> is open or bound to the length of <i>Substring</i> then <i>SubString</i> is searched in <i>LongString</i>. The first call finds the first <i>Pos</i>. Each recall finds the next <i>Pos</i> as long as there are any. The predicate fails when no more found.
</p>
<p>Example:</p>
<p>
<code>substring("Programs/Games/Chess.exe", 10, 5, S).</code><br/>
Returns <code>S</code> = <code>"Games"</code>.
</p>
</dd>
<!-- 1.5 -->
<dt><font size="+1"><b><code>term_str(</code><i>Domain</i><code>, </code><i>Term</i><code>, </code><i>String</i><code>)</code></b></font></dt>
<dd><p>Converts between terms and their string representations.</p>
<p>Example:</p>
<p><code>term_str(struct, a(3,"k"), S), %</code> binds <code>S</code> to the string <code>"a(3,\"k\")"</code>.</p>
<p><code>term_str(real, R, "3.141"), %</code> binds <code>R</code> to the number 3.141.
</dd>
<dt id="trap"><font size="+1"><b><code>trap(</code><i>Predicate_call</i><code>, </code>
<i>Var_exit</i><code>, </code><i>Exception_handler</i><code>)</code></b></font></dt>
<dd>
<p>Executes <i>Predicate_call</i>. If an exception happens or <a href="#exit"><code>exit</code></a> is called
within the call, the exit code is bound to <i>Var_exit</i>,
<i>Exception_handler</i> is called, and finally the whole <code>trap</code>
predicate fails.</p>
<p>Example:</p>
<pre>trap(analyze(Situation, Results), X, write("*** Exception ", X, '!'))
</pre>
</dd>
<dt id="upper_lower"><font size="+1"><b><code>upper_lower(</code><i>StringInUpperCase</i><code>, </code>
<i>StringInLowerCase</i><code>)</code></b></font></dt>
<dd>
<p>One of the parameters must be bound.</p>
<p>If only <i>StringInUpperCase</i> is bound then converts the string to lower case and binds it to <i>StringInLowerCase</i>.</p>
<p>If only <i>StringInLowerCase</i> is bound then converts the string to upper case and binds it to <i>StringInupperCase</i>.</p>
<p>If both parameters are bound compares parameters ignoring the case, and fails if they are not equivalent.</p>
<p>Example:</p>
<p><code>upper_lower("String", A).</code><br/>Returns <code>A</code> = <code>"string"</code></p>
</dd>
<dt><font size="+1"><b><code>write(</code><i>parameters</i><code>)</code></b></font></dt>
<dd>
<p>Writes the values of the parameters without punctuation or whitespace
in between.</p>
<p>Example:</p>
<p><code>write('a', "bc", 3.142)</code><br/>writes <code>abc3.142</code></p>
</dd>
<!-- 1.5 -->
<dt><font size="+1"><b><code>writedevice(</code><i>SymbolicFileName</i><code>)</code></b></font></dt>
<dd><p>If <i>SymbolicFileName</i> is bound, then reassigns the current write device to the file opened with the given <i>SymbolicFileName</i>. If the symbol is <code>screen</code>, then assigns the current write device to the standard output.</p>
<p>If <i>SymbolicFileName</i> is free, then binds <i>SymbolicFileName</i> to the current write device.</p>
<p>Example:</p>
<p><code>writedevice(Temp),</code></p>
<p><code>writedevice(report),</code></p>
<dt><font size="+1"><b><code>writeln(</code><i>parameters</i><code>)</code></b></font></dt>
<dd>
<p>As <code>write</code> but followed by <i>nl</i></p>
</dd>
<dt><font size="+1"><b><code>writeq(</code><i>parameters</i><code>)</code></b></font></dt>
<dd>
<p>Writes the values of the parameters in lexical notation so that they
can be read back. Strings are enclosed in double quotes and characters
are enclosed in single quotes.</p>
<p>Examples:</p>
<p><code>writeq('a', "bc", 3.142)</code></br>writes <code>'a'"bc"3.142</code>
</p>
<p><code>writeq(a('b', 'c'))</code></br>writes <code>a('b','c')</code>
</p>
</dd>
<dt><font size="+1"><b><i>Left</i> <code>=</code>
<i>Right</i></b></font></dt>
<dd>
<p>Tries to unify <i>Left</i> and <i>Right</i>.</p>
</dd>
<dt><font size="+1"><b>
<i>Left</i> <code>></code> <i>Right</i><br/>
<i>Left</i> <code>>=</code> <i>Right</i><br/>
<i>Left</i> <code><</code> <i>Right</i><br/>
<i>Left</i> <code><=</code> <i>Right</i><br/>
<i>Left</i> <code>!=</code> <i>Right</i><br/>
</b></font></dt>
<dd>
<p>
Compares arithmetically or lexicographically <i>Left</i> and <i>Right</i>.
</p>
</dd>
<!-- Template for additional stuff
<dt><font size="+1"><b>__</b></font></dt>
<dd>
</dd>
-->
</dl>
<h2>Arithmetic Expressions</h2>
<h3>Operators</h3>
<h4>Operator Precedence</h4>
<p>Arithmetic operators have their normal precedences. Expressions in
parenthesis <code>()</code> are evaluated first. Operators multiplication,
division, <code>mod</code>, and <code>div</code> have the same precedence
and are evaluated from left to right.</p>
<h4>Operators and Data Types</h4>
<table>
<tr style="border-bottom: 1px solid">
<th>Symbol</th>
<th>Operation</th>
<th>Left Type</th>
<th>Right Type</th>
<th>Result Type</th>
<th>Example</th>
<th>Example Value</th>
</tr>
<tr>
<td><code>*</code></td>
<td>multiplication</td>
<td>integer</td>
<td>integer</td>
<td>integer</td>
<td><code>2 * 3</code></td>
<td>6</td>
</tr>
<tr>
<td><code>*</code></td>
<td>multiplication</td>
<td>integer</td>
<td>real</td>
<td>real</td>
<td><code>2 * 3.2</code></td>
<td>6.4</td>
</tr>
<tr>
<td><code>*</code></td>
<td>multiplication</td>
<td>real</td>
<td>integer</td>
<td>real</td>
<td><code>2.2 * 3</code></td>
<td>6.6</td>
</tr>
<tr>
<td><code>*</code></td>
<td>multiplication</td>
<td>real</td>
<td>real</td>
<td>real</td>
<td><code>2.2 * 3.2</code></td>
<td>7.04</td>
</tr>
<tr>
<td><code>/</code></td>
<td>division</td>
<td>integer</td>
<td>integer</td>
<td>real</td>
<td><code>3 / 2</code></td>
<td>1.5</td>
</tr>
<tr>
<td><code>/</code></td>
<td>division</td>
<td>integer</td>
<td>real</td>
<td>real</td>
<td><code>4 / 2.5</code></td>
<td>1.6</td>
</tr>
<tr>
<td><code>/</code></td>
<td>division</td>
<td>real</td>
<td>integer</td>
<td>real</td>
<td><code>6.8 / 4</code></td>
<td>1.7</td>
</tr>
<tr>
<td><code>/</code></td>
<td>division</td>
<td>real</td>
<td>real</td>
<td>real</td>
<td><code>14.7 / 4.2</code></td>
<td>3.5</td>
</tr>
<tr>
<td><code>div</code></td>
<td>integer division</td>
<td>integer</td>
<td>integer</td>
<td>integer</td>
<td><code>5 div 3</code></td>
<td>1</td>
</tr>
<tr style="border-bottom: 1px solid">
<td><code>mod</code></td>
<td>remainder</td>
<td>integer</td>
<td>integer</td>
<td>integer</td>
<td><code>5 mod 3</code></td>
<td>2</td>
</tr>
<tr>
<td><code>+</code></td>
<td>addition</td>
<td>integer</td>
<td>integer</td>
<td>integer</td>
<td><code>2 + 3</code></td>
<td>5</td>
</tr>
<tr>
<td><code>+</code></td>
<td>addition</td>
<td>integer</td>
<td>real</td>
<td>real</td>
<td><code>2 + 3.2</code></td>
<td>5.2</td>
</tr>
<tr>
<td><code>+</code></td>
<td>addition</td>
<td>real</td>
<td>integer</td>
<td>real</td>
<td><code>2.2 + 3</code></td>
<td>5.2</td>
</tr>
<tr>
<td><code>+</code></td>
<td>addition</td>
<td>real</td>
<td>real</td>
<td>real</td>
<td><code>2.2 + 3.2</code></td>
<td>5.4</td>
</tr>
<tr>
<td><code>-</code></td>
<td>subtraction</td>
<td>integer</td>
<td>integer</td>
<td>integer</td>
<td><code>3 - 2</code></td>
<td>1</td>
</tr>
<tr>
<td><code>-</code></td>
<td>subtraction</td>
<td>integer</td>
<td>real</td>
<td>real</td>
<td><code>3 - 2.2</code></td>
<td>0.8</td>
</tr>
<tr>
<td><code>-</code></td>
<td>subtraction</td>
<td>real</td>
<td>integer</td>
<td>real</td>
<td><code>3.2 - 2</code></td>
<td>1.2</td>
</tr>
<tr>
<td><code>-</code></td>
<td>subtraction</td>
<td>real</td>
<td>real</td>
<td>real</td>
<td><code>3.2 - 2.2</code></td>
<td>1.0</td>
</tr>
<tr>
<td><code>+</code></td>
<td>identity function</td>
<td></td>
<td>integer</td>
<td>integer</td>
<td><code>+ 3</code></td>
<td>3</td>
</tr>
<tr>
<td><code>+</code></td>
<td>identity function</td>
<td></td>
<td>real</td>
<td>real</td>
<td><code>+ 3.2</code></td>
<td>3.2</td>
</tr>
<tr>
<td><code>-</code></td>
<td>negation</td>
<td></td>
<td>integer</td>
<td>integer</td>
<td><code>- 2</code></td>
<td>-2</td>
</tr>
<tr>
<td><code>-</code></td>
<td>negation</td>
<td></td>
<td>real</td>
<td>real</td>
<td><code>- 2.2</code></td>
<td>-2.2</td>
</tr>
</table>
<!--
<p></p>
<dt><font size="+1"><b><code>sin(</code><i>Expression</i><code>)</code></b></font></dt>
<dd><p>Calculates sine of the value of <i>Expression</i>.</p>
<p>Example:</p>
<p><code>sin(Alpha*K)</code></p>
</dd>
<p>
unary + ja -
binary + - * , integer tai real. real, jos toinen on real, muuten integer
/ - tulos aina real
mod div vain integereille
</p>
<dl>
<dt><font size="+1"><b><code>sin(</code><i>Expression</i><code>)</code></b></font></dt>
<dd><p>Calculates sine of the value of <i>Expression</i>.</p>
<p>Example:</p>
<p><code>sin(Alpha*K)</code></p>
</dd>
</dl>
<h2>Built-in Functions</h2>
<dl>
<dt><font size="+1"><b><code>sin(</code><i>Expression</i><code>)</code></b></font></dt>
<dd><p>Calculates sine of the value of <i>Expression</i>.</p>
<p>Example:</p>
<p><code>sin(Alpha*K)</code></p>
</dd>
</dl>
-->
<h2>Other Details</h2>
<H3 id="ConsultDirname">ConsultDirname</H3>
<DL>
<DD>
Directory names can refer to directories either in the file system or in the
resource system. In order to specifically refer
to the file system prepend the name
with "<code>file:</code>". In order to refer to a directory in the resource system
prepend the name with "<code>res:</code>". If neither is specified and the
ConsultDirname is an absolute path it refers to the file system. A relative path
refers to a subdirectory of the current work directory except in consult directory.
<DL>
<DT><B>Examples:</B>
<DD><CODE>"file:C:/data"</CODE> - refers to the data directory at the root of
the C disk.</DD>
<DD><CODE>"res:lib/routes"</CODE> - refers to a resource directory.</DD>
<DD><CODE>"sub"</CODE> - refers to the subdirectory <code>sub</code> of
the current consult directory.</DD>
</DL>
</DD>
</DL>
<H3 id="filename">filename</H3>
<DL>
<DD>
File names can refer either to files in the file system or to
resources of the jar package.
In order to specifically refer
to the file system prepend the name
with "<code>file:</code>". In order to refer to a resource in the resource system
prepend the name with "<code>res:</code>". If neither is specified and the
filename is an absolute path it refers to the file system. A relative path
refers to a file or resource in the current directory except that the predicates
<code>consult</code> and <code>include</code> use current consult directory instead.
<DL>
<DT><B>Examples:</B>
<DD><CODE>"file:C:/data/trees.pro"</CODE> - refers to a file in the file
system.
<DD><CODE>"res:parameters.pro"</CODE> - refers to a resource in the resource system.
<DD><CODE>"rules.pro"</CODE> - refers to a file or a resource in the current
directory.
</DL>
</DD>
</DL>
</body>
</html>