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 (97 lines) | stat: -rw-r--r-- 2,092 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
=================================================================
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(dynpred(loader)).
...


% sending to descendant the message p/1, returns the definition in root:

| ?- descendant::p(Value).

Value = root
yes


% asserting a local definition for p/1 in descendant overrides the inherited 
% definition:

| ?- descendant::(assertz(p(descendant)), p(Value)).

Value = descendant
yes


% if we retract the local definition, again the definition inherited from root
% will be used:

| ?- descendant::(retractall(p(_)), p(Value)).

Value = root
yes


% class does not understand the message p1/1 (the predicate is declared only 
% for the class descendant instances):

| ?- class::p1(X).

error(existence_error(predicate_declaration, p1(_)), class::p1(_), user)


% the same message is valid for the class instances:

| ?- instance::p1(X).

X = class
yes


% if we assert a clause for a new predicate, p2/1, in the class
% (a side-effect being a dynamic declaration of the predicate):

| ?- class::assertz(p2(class)).

yes


% the new predicate, like p1/1, is not available for the class:

| ?- class::p2(Value).

error(existence_error(predicate_declaration, p2(_)), class::p2(_), user)


% but is available for the class instances, the same way as p1/1:

| ?- instance::p2(X).

X = class
yes


% using a prototype, assert three new predicates (the method object_assert/0 
% asserts the predicate public_predicate/0 from outside the prototype; the 
% method self_assert/0 asserts the predicate protected_predicate/0 in self; 
% the method this_assert/0 asserts the predicate private_predicate/0 in this):

| ?- prototype::(object_assert, self_assert, this_assert).

yes


% and check the resulting scope of each predicate:

| ?- prototype::dynamic_predicates.

public_predicate/0 - public
protected_predicate/0 - protected
private_predicate/0 - private
yes