File: SCRIPT

package info (click to toggle)
yap 5.1.1-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 16,124 kB
  • ctags: 14,650
  • sloc: ansic: 122,796; perl: 22,545; sh: 3,768; java: 1,277; makefile: 1,191; xml: 739; tcl: 624; lisp: 142; awk: 9
file content (110 lines) | stat: -rw-r--r-- 1,942 bytes parent folder | download
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
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.27.1

Copyright (c) 1998-2006 Paulo Moura.  All Rights Reserved.
=================================================================


% start by loading the example:

| ?- logtalk_load(viewpoints(loader)).
...


% we can start by asking joe its age:

| ?- joePerson::age(Age).

Age = 30
yes


% the same question could be made via any of its viewpoints:

| ?- joeSportsman::age(Age).

Age = 30
yes


% now let's tell joe to get older:

| ?- joePerson::getOlder.

yes


% we can verify the effect of the above message from any of the viewpoints:

| ?- joeChessPlayer::age(Age).

Age = 31
yes


% because the growOld/0 and the age/1 predicates are implemented using 
% property sharing, we can send the getOlder/0 message to any viewpoint:

| ?- joeEmployee::getOlder.

yes


% we can check this by asking joe its age:


| ?- joePerson::age(Age).

Age = 32
yes


% as you can see, although the modification message have been sent to a 
% descendant, its the predicate age/1 in the parent that got updated


% to illustrate value sharing we use a couple of predicates, score/1 and
% setScore/0, defined in joePerson:


| ?- joePerson::score(Score).

Score = 0
yes


% initially, score/1 is only defined for joePerson, so every descendant 
% or viewpoint will share its value/definition:

| ?- joeEmployee::score(Score).

Score = 0
yes


% but if we decide to increment the counter by sending the setScore/0 
% message to a descendant:

| ?- joeChessPlayer::(setScore(2200), score(Score)).

Score = 2200
yes


% then the descendant will now have a local definition for counter/1,
% independent of the definition in its parent, joePerson:

| ?- joePerson::score(Score).

Score = 0
yes


% the other descendants/viewpoints will continue to share the definition 
% in joePerson:

| ?- joeSportsman::score(Score).

Score = 0
yes