1Sugar(3)              User Contributed Perl Documentation             Sugar(3)
2
3
4

NAME

6       Language::Prolog::Sugar - Syntactic sugar for Prolog term constructors
7

SYNOPSIS

9         use Language::Prolog::Sugar vars => [qw(X Y Z)];
10
11         use Language::Prolog::Sugar functors =>{ equal => '=',
12                                                  minus => '-' };
13
14         use Language::Prolog::Sugar functors =>[qw(is)];
15
16         use Language::Prolog::Sugar atoms =>[qw(foo bar)];
17
18         use Language::Prolog::Sugar atoms =>{ cut => '!' };
19
20         use Language::Prolog::Sugar chains =>{ andn => ',',
21                                                orn => ';' };
22
23
24         $term=andn( equal(X, foo),
25                     orn( equal(Y, [4, bar]),
26                          equal(Y, foo)),
27                     cut,
28                     is(Z, minus(34, Y)));
29

ABSTRACT

31       This module allows you to easily define constructor subs for Prolog
32       terms.
33

DESCRIPTION

35       Language::Prolog::Sugar is able to export to the calling package a set
36       of subrutines to create Prolog terms as defined in the
37       Language::Prolog::Types module.
38
39       Perl programs using these constructors have the same look as real
40       Prolog programs.
41
42       Unfortunately Prolog operators syntax could not be simulated in any way
43       I know (well, something could be done using overloading, but just
44       something).
45
46   EXPORT
47       Whatever you wants!
48
49       Language::Prolog::Sugar can create constructors for four Prolog types:
50       atoms, functors, vars and chains.
51
52       The syntax to use it is as follows:
53
54         use Language::Prolog::Sugar $type1s=>{ $name1 => $prolog_name1,
55                                                $name2 => $prolog_name2,
56                                               ... },
57                                     ...
58
59       or
60
61         use Language::Prolog::Sugar $type2s=>[qw($name1 $name2 ...)],
62                                     ...
63
64       $type1s, $type2s, ... are "atoms", "functors", "vars" or "chains".
65
66       $name1, $name2, ... are the names of the subrutines exported to the
67       caller package.
68
69       $prolog_name, $prolog_name2, ... are the names that the constructors
70       use when making the Prolog terms.
71
72       i.e:
73
74         use Language::Prolog::Sugar atoms=>{ cut => '!' }
75
76       exports a subrutine "cut" that when called returns a Prolog atom "!".
77
78         use Language::Prolog::Sugar functor=>{ equal => '=' }
79
80       exports a subrutine "equal" that when called returns a Prolog functor
81       "=".
82
83         equal(3,4)
84
85       returns
86
87         '='(3,4)
88
89       It should be noted that functor arity is inferred from the number of
90       arguments:
91
92         equal(3, 4, 5, 6, 7)
93
94       returns
95
96         '='(3, 4, 5, 6, 7)
97
98       I call 'chain' the structure formed tipically by ','/2 or ';'/2
99       operators in Prolog programs. i.e., Prolog program
100
101         p, o, r, s.
102
103       is actually
104
105         ','(p, ','(o, ','(r, s))).
106
107       using chains allows for a more easily composition of those structures:
108
109         use Language::Prolog::Sugar chains => { andn => ',' },
110                                     atoms => [qw(p o r s)];
111
112       and
113
114         andn(p, o, r, s)
115
116       generates the Prolog structure for the example program above.
117
118       Also, the tag "auto_term" can be used to install and AUTOLOAD sub on
119       the caller module that would make a functor, term or variable for every
120       undefined subroutine. For instance:
121
122         use Language::Prolog::Sugar 'auto_term';
123         swi_call(use_module(library(pce)));
124         swi_call(foo(hello, Hello))
125
126       The old "auto_functor" tag has been obsoleted.
127

SEE ALSO

129       Language::Prolog::Types, Language::Prolog::Types::Factory
130
132       Copyright 2002-2006 by Salvador FandiƱo (sfandino@yahoo.com).
133
134       This library is free software; you can redistribute it and/or modify it
135       under the same terms as Perl itself.
136
137
138
139perl v5.32.0                      2020-07-28                          Sugar(3)
Impressum