1Language::Prolog::TypesU(s3e)r Contributed Perl DocumentaLtainognuage::Prolog::Types(3)
2
3
4
6 Language::Prolog::Types - Prolog types in Perl.
7
9 use Language::Prolog::Types::overload;
10
11 use Language::Prolog::Types qw(:ctors);
12
13 $atom=prolog_atom('foo');
14 $list=prolog_list(1,2,3,4,5);
15 $functor=prolog_functor('foo',1,2,3,'bar');
16 $nil=prolog_nil;
17
18
19 use Language::Prolog::Types qw(:is);
20
21 print "$atom is an atom\n" if prolog_is_atom($atom);
22 print "$list is a list\n" if prolog_is_list($list);
23 print "$nil is nil\n" if prolog_is_nil($nil);
24
25
26 use Language::Prolog::Types qw(:short);
27
28 $atom=A('foo');
29 $list=L(1,2,3,4);
30 $functor=F('foo',1,2,3,'bar')
31
32 print "$atom is an atom\n" if isA($atom);
33 print "$list is a list\n" if isL($list);
34 print "$nil is nil\n" if isN($nil);
35
37 Language::Prolog::Types is a set of modules implementing Prolog types
38 in Perl.
39
41 This module exports subroutines to create Prolog terms in Perl, to test
42 term types and also some utility functions to convert data between
43 Prolog and Perl explicitly.
44
45 You will see that there is not any kind of constructor for Prolog
46 atoms, this is because Perl scalars (numbers or strings) are directly
47 used as Prolog atoms.
48
49 You can also use Perl list references as Prolog lists, and Perl "undef"
50 as Prolog nil ("[]").
51
52 EXPORT_TAGS
53 Subroutines are grouped in three tags:
54
55 ":is"
56 Subroutines to test typing of terms.
57
58 "prolog_is_atom($term)"
59 true if $term is a valid Prolog atom (Perl number or string).
60
61 "prolog_is_nil($term)"
62 true if $term is Prolog nil "[]". Perl undef is equivalent to
63 Prolog nil.
64
65 "prolog_is_list($term)"
66 true if $term is Prolog list.
67
68 It should be noted that Prolog nil although represented with
69 the empty list "[]" is not a list.
70
71 "prolog_is_list_or_nil($term)"
72 true if $term is a Prolog list or nil.
73
74 "prolog_is_functor($term)"
75 true if $term is a Prolog functor.
76
77 It should be noted that list are formed with the functor '.'/2.
78
79 "prolog_is_variable($term)"
80 "prolog_is_var($term)"
81 true if $term is a Prolog variable.
82
83 "prolog_is_ulist($term)"
84 true if $term is a Prolog unfinished list (those whose tail is
85 not nil).
86
87 "prolog_is_string($term)"
88 true if $term can be converted to a string, a list whose
89 elements are integers in the range [0..255].
90
91 ":ctors"
92 Subruotines to create new Prolog terms.
93
94 "prolog_list(@terms)"
95 returns a new prolog list with elements @terms.
96
97 "prolog_ulist(@terms, $tail)"
98 returns a new prolog unfineshed list with elements @terms and
99 tail $tail.
100
101 "prolog_functor($name, @args)"
102 returns a new prolog functor which name $name and arguments
103 @args.
104
105 "prolog_variable($name)"
106 "prolog_var($name)"
107 returns a new prolog variable with name $name.
108
109 "prolog_atom($atom)"
110 As normal Perl strings and numbers are used to represent Prolog
111 atoms this function only ensures that its argument is properly
112 converted to a string.
113
114 "prolog_nil()"
115 returns Prolog nil ("[]").
116
117 "prolog_string($string)"
118 returns Prolog string, that is a list with the ASCII codes of
119 $string.
120
121 "prolog_chain($ftr, $term1, $term2, ..., $termn, $termo)"
122 creates prolog structure
123
124 $ftr($term1,
125 $ftr($term2,
126 $ftr($term3,
127 $ftr(...
128 $ftr($termn, $termo) ... ))))
129
130 it should be noted that
131
132 prolog_chain($ftr, $term)
133
134 returns
135
136 $term
137
138 "prolog_opaque($object)"
139 creates a proxy opaque object to tell Perl to pass the object
140 to Prolog as an opaque reference that can not be directly used
141 from Prolog but just passed back to Perl in callbacks.
142
143 ":util"
144 Subroutines to convert Prolog data to Perl.
145
146 "prolog_list2perl_list($term)"
147 converts a Prolog_list to a Perl array acounting for all the
148 different possibilities of Prolog list representations.
149
150 "prolog_list2perl_string($term)"
151 converts a Prolog list to a Perl string. All the elements in
152 the list have to be integers in the range [0..255] or an
153 exception will be raised.
154
155 ":short"
156 For the lazy programmer, ":short" includes a set of abreviations
157 for the ":is" and ":ctors" groups:
158
159 "isL($term)"
160 "isUL($term)"
161 "isF($term)"
162 "isV($term)"
163 "isA($term)"
164 "isN($term)"
165 "isS($term)"
166 "L(@terms)"
167 "UL(@terms, $tail)"
168 "F($name, @args)"
169 "V($name)"
170 "A($atom)"
171 "N()"
172 "S($string)"
173 "C($term1, $term2, ..., $termn, $termo)"
174
176 Language::Prolog::Types::overload
177
178 Language::Prolog::Sugar
179
180 Language::XSB
181
183 Copyright 2002-2005, 2007 by Salvador FandiƱo <sfandino@yahoo.com>.
184
185 This library is free software; you can redistribute it and/or modify it
186 under the same terms as Perl itself.
187
188
189
190perl v5.34.0 2022-01-21 Language::Prolog::Types(3)