hi Ely,
The easiest way to write such a method is shown below.
I realize that this might not be exactly how OO languages like
Java do it but it is simple and effective.
Chapter 22 of the Ergo manual (Inheritance of Default
Properties and Types) discusses inheritance in Ergo and Ch
22.6
Code Inheritance deals with the issue of a version of
inheritance that is closer to what is going on in procedural OO
languages.
I am not suggesting, however, that sticking with the way procedural languages do code inheritance is any better than the straightforward option that exists in Ergo.
Here is now count() can be defined in Ergo.
Set[|
members->{},
count->0
|].
set1:Set[members->{K,L}].
set1[members->{M}].
set2:Set[members->{A,B,C}].
// a def for the method count.
?X[count->?C] :-
?C = count{?m| ?X:Set[members->?m]}.
ergo> s[count->?X]. // nonexisting set
?X = 0
Yes
ergo> set1[count->?X].
?X = 3
Yes
ergo> set2[count->?X].
?X = 3
Yes
Set[|
members->{},
count->0
|].
Set[|
members->{},
count->0
|].
set1:Set[members->{K,L}].
set1[members->{M}].
set2:Set[members->{A,B,C}].
set3:Set.
?X[count->?C] :- ?X:Set, ?C = count{?m| ?X[members->?m]}.
?X[empty] :- ?X:Set[count->0].
?X[%delete(?M)] :- ?X:Set[members->?M],
tdelete{?X[members->?M]}.
?X[%insert(?M)] :- ?X:Set, isnonvar{?M},
tinsert{?X[members->?M]}.
ergo> set2[%delete(A)].
Yes
ergo> set2[%insert(123)].
Yes
ergo> set2[members->?m].
?m = 123
?m = B
?m = C
Yes
ergo> set2[empty].
No
ergo> set3[empty].
Yes
If think methods like that fall in the same previous issue about methods that modify data from own object. I've read the section 22 but, as you said, maybe ergoAI has a more direct method for that.
I am not aware of any such issue.
Sec. 22.6 talks about simulation of code inheritance, which is
not provided organically in ErgoAI because it complicates the
language while providing no additional important functionality.
ErgoAI has other ways to do what you want, as you can see from the
above examples.
--
--- michael
Thanks!Sorry by word "issue" :-) English is not my native language... I meant something like "the same question that I cited in the previous email". :-)
You asked how to access the self object. I showed how to do what you want, so it is unclear what is still unclear.
That problem with "self" does not even arise in F-logic.
Procedural languages do have this minor "issue", but it is usually
solved by adding simple constructs. In ErgoAI, no special
constructs are needed for that.
Where can I find reference to use "%" ?
Look for "Transactional methods", 24.1, 24.2.
--
--- michael