| 1 | ================================================================ |
|---|
| 2 | Logtalk - Open source object-oriented logic programming language |
|---|
| 3 | Release 2.35.0 |
|---|
| 4 | |
|---|
| 5 | Copyright (c) 1998-2009 Paulo Moura. All Rights Reserved. |
|---|
| 6 | Logtalk is free software. You can redistribute it and/or modify |
|---|
| 7 | it under the terms of the "Artistic License 2.0" as published by |
|---|
| 8 | The 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 | |
|---|
| 22 | Syntax error: Operator expected |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | % you must use instead functor notation: |
|---|
| 26 | |
|---|
| 27 | | ?- double::double(I, J). |
|---|
| 28 | |
|---|
| 29 | I = 1 |
|---|
| 30 | J = 2 ; |
|---|
| 31 | |
|---|
| 32 | I = 2 |
|---|
| 33 | J = 4 ; |
|---|
| 34 | |
|---|
| 35 | I = 3 |
|---|
| 36 | J = 6 |
|---|
| 37 | |
|---|
| 38 | yes |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | % operators also affect inputing of terms, enabling this example to work: |
|---|
| 42 | |
|---|
| 43 | | ?- triple::triple(I, J). |
|---|
| 44 | |
|---|
| 45 | I = 1 |
|---|
| 46 | J = 3 ; |
|---|
| 47 | |
|---|
| 48 | I = 2 |
|---|
| 49 | J = 6 ; |
|---|
| 50 | |
|---|
| 51 | I = 3 |
|---|
| 52 | J = 9 |
|---|
| 53 | |
|---|
| 54 | yes |
|---|
| 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). |
|---|
| 64 | uncaught 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 | |
|---|
| 71 | N1 = a |
|---|
| 72 | N2 = b ; |
|---|
| 73 | |
|---|
| 74 | N1 = a |
|---|
| 75 | N2 = c ; |
|---|
| 76 | |
|---|
| 77 | N1 = b |
|---|
| 78 | N2 = d ; |
|---|
| 79 | |
|---|
| 80 | N1 = c |
|---|
| 81 | N2 = d |
|---|
| 82 | |
|---|
| 83 | yes |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | | ?- graph1::path(a, d, Path). |
|---|
| 87 | |
|---|
| 88 | Path = [a, b, d] ; |
|---|
| 89 | |
|---|
| 90 | Path = [a, c, d] |
|---|
| 91 | |
|---|
| 92 | yes |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | % confirm that the "edge" operator have not became global: |
|---|
| 96 | |
|---|
| 97 | | ?- current_op(P, T, edge). |
|---|
| 98 | |
|---|
| 99 | no |
|---|