root/trunk/examples/operators/SCRIPT.txt

Revision 4662, 1.6 KB (checked in by pmoura, 6 days ago)

Updated copyright notice.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1================================================================
2Logtalk - Open source object-oriented logic programming language
3Release 2.35.0
4
5Copyright (c) 1998-2009 Paulo Moura.        All Rights Reserved.
6Logtalk is free software.  You can redistribute it and/or modify
7it under the terms of the "Artistic License 2.0" as published by
8The Perl Foundation. Consult the "LICENSE.txt" file for details.
9================================================================
10
11
12% start by loading the example:
13
14| ?- logtalk_load(operators(loader)).
15...
16
17
18% operators declared inside an object are not visible outside:
19
20| ?- double::(I double J).
21
22Syntax error: Operator expected
23
24
25% you must use instead functor notation:
26
27| ?- double::double(I, J).
28
29I = 1
30J = 2 ;
31
32I = 2
33J = 4 ;
34
35I = 3
36J = 6
37
38yes
39
40
41% operators also affect inputing of terms, enabling this example to work:
42
43| ?- triple::triple(I, J).
44
45I = 1
46J = 3 ;
47
48I = 2
49J = 6 ;
50
51I = 3
52J = 9
53
54yes
55
56
57% check the file "previous.txt" generated from the file "next.txt" by the object "reverse"
58% by opening the files on a text editor
59
60
61% the "edge" operator on the "local.lgt" source file is not globally visible:
62
63| ?- graph1::(N1 edge N2).
64uncaught exception: error(syntax_error('user_input:10 (char:13) ) or operator expected'),read_term/3)
65
66
67% you must use instead functor notation:
68
69| ?- graph1::edge(N1, N2).
70
71N1 = a
72N2 = b ;
73
74N1 = a
75N2 = c ;
76
77N1 = b
78N2 = d ;
79
80N1 = c
81N2 = d
82
83yes
84
85
86| ?- graph1::path(a, d, Path).
87
88Path = [a, b, d] ;
89
90Path = [a, c, d]
91
92yes
93
94
95% confirm that the "edge" operator have not became global:
96
97| ?- current_op(P, T, edge).
98
99no
Note: See TracBrowser for help on using the browser.