-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathals_python_guide.html
119 lines (90 loc) · 2.01 KB
/
als_python_guide.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
<html>
<head>
<title>ALS Prolog/Python Guide</title>
</head>
<body>
<h1>ALS Prolog to Python Interface</h1>
<p>
The ALS Prolog to Python interface is a Prolog Shared Library which
embeds a Python interpreter within ALS Prolog. Prolog can execute
Python command and pass basic data type to and from the Python
interpreter.
</p>
<p>
The Interface requires that Python 1.5 or better has been installed
on the system.
</p>
<h2>Example</h2>
<p>
A simple example of loading the Python interface and calling
its predicates.
<p>
<pre>
?- [python].
yes.
% Set the Python variable a to 2.
?- py_exec('a = 2').
yes.
% Check that the variable a evaluates to 2
?- py_eval('a', X).
X = 2
yes.
% Call the atoi function in the string module to
% convert a hexedicimal string to an integer.
?- py_call(string, atoi('3f0', 16), X).
X = 1008
yes.
</pre>
<h2>Data Type Conversions</h2>
<p>
</p>
<table>
<tr><td>Python</td><td>Prolog</td></tr>
<tr><td>integer</td><td>integer (or float for large integers)</td></tr>
<tr><td>float</td><td>float</td></tr>
<tr><td>string</td><td>atom (uninterned)</td></tr>
<tr><td>lists</td><td>lists</td></tr>
<tr><td>tuples</td><td>comma lists, or '()' for the empty tuple</td></tr>
</table>
<!--
limitations - maxint on prolog - produces exception
floating point
limitations
strings
limitations
lists
limitations
tuples
limitations
Other types - exception
-->
<h2>Python Interface Predicates</h2>
<p>
py_exec(command).
</p>
<p>
Executes the statement <em>command</em> in the Python interpreter.
</p>
<p>
py_eval(expr, result).
</p>
<p>
Evaluates the expression <em>expr</em> in the Pyton interpreter and
unifies the value of the expression with <em>result</em>.
</p>
<p>
py_call(mod, func(args..), result).
</p>
<p>
Calls the function <em>func</em> in the module <em>mod</em> and unifies
the result with <em>result</em>.
</p>
<p>
The arguments can include keyword arguments, which take the form key=value.
</p>
<!--
Limitations of using Python from ALS Prolog
standard out not mapped in IDE.
-->
</body>
</html>