Changeset 2911
- Timestamp:
- 05/10/05 02:16:17 (4 years ago)
- svk:copy_cache_prev:
- 4437
- Files:
-
- 3 modified
-
ext/Perl-MetaClass/lib/Perl/MetaAssoc.pm (modified) (3 diffs)
-
ext/Perl-MetaClass/lib/Perl/MetaClass.pm (modified) (3 diffs)
-
src/Pugs/Class.hs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
ext/Perl-MetaClass/lib/Perl/MetaAssoc.pm
r2905 r2911 7 7 sub Perl::MetaAssoc::new(Str $class) returns Str is export { 8 8 ($class.instance_isa('Perl::MetaClass')) 9 || die "Class must be a Perl::MetaClass instance"; 9 || die "Class must be a Perl::MetaClass instance"; 10 10 my $id = make_instance("Perl::MetaAssoc", { 11 11 'class' => $class, # Perl::MetaClass … … 13 13 'range' => [0, Inf], # Range 14 14 'isComposite' => (0 == 1), # Bool 15 'ordered' => (0 == 1), # Bool 16 'keyed' => (0 == 1), # Bool 17 'companion' => undef, # Str 15 'ordered' => (0 == 1), # Bool 16 'keyed' => (0 == 1), # Bool 17 'companion' => undef, # Str 18 18 }); 19 19 return $id; 20 20 } 21 21 22 # XXX - we need to follow these (?): 23 # 24 # ∃ MetaClass A, MetaAssoc C : A.clsAssoc ∋ C ↔ C.assocClass = A 25 # (meta-class to meta-assoc is one-to-many, but meta-assoc to meta-class is one-to-one) <- am I right here? 26 # 27 # ∃ MetaAssoc C₁, C₂ : C₁.assocPair = C₂ ↔ C₂.assocPair = C₁ 22 23 # ∀ MetaAssoc C₁, C₂ : C₁.assocPair = C₂ ↔ C₂.assocPair = C₁ 28 24 # (this is just bi-directional pairing of the two associations) 29 # 25 # 30 26 # -- can't be composite both ways 31 # 32 # ∃ MetaAssoc C₁, C₂ : C₁.assocPair = C₂ ∧ C₁.assocIsComposite 33 # → ¬(C₂.catIsComposite) 34 # 27 # 28 # 35 29 # -- this seems the simplest way to specify complementary categories 36 # 37 # ∃ MetaAssoc C₁, C₂, MetaClass M₁, M₂ 38 # : C₁.assocPair = C₂ ∧ C₁.assocClass = M₁ ∧ C₂.assocClass = M₂ 39 # → ( ∃ M₁.clsAssoc{C₂.assocCompanion} 40 # ∧ ∃ M₂.clsAssoc{C₁.assocCompanion} 41 # ∧ M₁.clsAssoc{C₂.assocCompanion}[1] = C₁ 42 # ∧ M₂.clsAssoc{C₁.assocCompanion}[1] = C₂ 43 # ∧ M₁.clsAssoc{C₂.assocCompanion}[0] = M₂.clsAssoc{C₁.assocCompanion}[0] 44 # ) 30 # 31 # 32 # This is the rule that 45 33 46 34 … … 96 84 use Perl::MetaAssoc; 97 85 86 # represent a one to many relationship between the 87 # "Property" and "Class" MetaClasses. The association is 88 # called .properties on the Class end, and .class on the 89 # property end. 90 91 my $Property_mc = Perl::MetaClass->new("Property"); 92 my $Class_mc = Perl::MetaClass->new("Class"); 93 94 $Class_mc->clsAssocs 95 (properties => Perl::MetaAssoc->new 96 ( 97 assocOrdered => false, 98 assocRange => [0, inf], 99 assocCompanion => "class", 100 assocIsComposite => true, 101 assocPair => Perl::MetaAssoc->new 102 ( assocRange => [1, 1], 103 assocClass => $Property_mc ) 104 ) 105 ); 106 98 107 =head1 DESCRIPTION 108 109 A Perl::MetaAssoc represents a fairly abstract concept. Firstly, it 110 is a class of the B<meta-model>, which is not C<Class.meta()> objects 111 at all. That distinction is explained at L<Perl::MetaClass>. 112 113 This class is used to describe I<relationships> between two classes in 114 the Class model. For instance, a Class can have any number of defined 115 methods, and each method can only belong to one class. These two 116 comments are frequently viewed as being seperate relationships, but in 117 fact they are simply different ways of looking at the same 118 relationship; that a method belongs to exactly one class (or package, 119 or whatever). 120 121 Each side of the relationship is identical to the other; so, in this 122 metamodel, relationships are represented with I<two> objects - one for 123 each side. 124 125 There is a lot of implicit 'magic' assumed to be happening in the 126 example. This magic stems from rules such as the following; 127 128 ∀ MetaClass A, MetaAssoc C : A.clsAssoc ∋ C ↔ C.assocClass = A 129 130 This is read as "For every MetaClass A and MetaAssoc C, such that 131 A.clsAssoc contains C, it is automatically implied that C.assocClass 132 is A". 133 134 We could have written this explicitly: 135 136 my $properties_class_ma = Perl::MetaAssoc->new(); 137 $Class_mc->clsAssocs("properties" => $properties_class_ma); 138 $properties_class_ma->assocClass($Class_mc); 139 140 However, this would be needless duplication of expressing the 141 relationship; we want this all to happen automatically. 142 143 This rule is almost identical: 144 145 ∀ MetaAssoc C₁, C₂ : C₁.assocPair = C₂ ↔ C₂.assocPair = C₁ 146 147 Just by stating that the C<assocPair> for one of the C<MetaAssoc> 148 objects is the other, we don't need to specify the reverse relation. 149 150 Similarly, as we have stated; 151 152 ∀ MetaAssoc C₁, C₂, MetaClass M₁, M₂ 153 : C₁.catPair = C₂ ∧ C₁.assocCompanion 154 ∧ C₁.catClass = M₁ ∧ C₂.catClass = M₂ 155 → ( ∃ M₁.clsAssocs{C₂.catCompanion} 156 ∧ ∃ M₂.clsAssocs{C₁.catCompanion} 157 ∧ M₁.clsAssocs{C₂.catCompanion}[1] = C₁ 158 ∧ M₂.clsAssocs{C₁.catCompanion}[1] = C₂ 159 ∧ M₁.clsAssocs{C₂.catCompanion}[0] = M₂.clsAssocs{C₁.catCompanion}[0] 160 ) 161 162 Then simply by specifying that the C<properties> MetaAssoc object's 163 companion is called "class", this will mean that its pair MetaAssoc 164 object's name within the "Property" clsAssocs collection is "class". 165 It also implies that the pair MetaAssoc will have a C<companion> 166 property of "properties". 167 168 Finally, it is implied that the other side of the association cannot 169 be composite; 170 171 ∀ MetaAssoc C₁, C₂ : C₁.assocPair = C₂ ∧ C₁.assocIsComposite 172 → ¬(C₂.catIsComposite) 99 173 100 174 =head1 AUTHORS -
ext/Perl-MetaClass/lib/Perl/MetaClass.pm
r2910 r2911 29 29 # NOTE: 30 30 # the next 2 methods enforce the rule; 31 # ∃MetaClass A, B | A.clsSuper = B ↔ A ∈ B.clsSubClasses31 # ∀ MetaClass A, B | A.clsSuper = B ↔ A ∈ B.clsSubClasses 32 32 # which in english means: 33 33 # A is a superclass of B and A is found within B's list of subclasses … … 73 73 } 74 74 75 # XXX -- what do we do about visibility here? 76 # is it a property of the MetaProperty? or is 77 # it a property of the relationship with the 78 # MetaClass? 79 75 # visibility is not as important on the MetaModel as it is on the real 76 # Class Model. 80 77 sub clsProperties(Str $inv: Array *@properties) returns Hash { 81 78 my %self := get_instance($inv, "Perl::MetaClass"); … … 128 125 129 126 =head1 SYNOPSIS 130 127 131 128 # Package 132 129 # | -
src/Pugs/Class.hs
r2908 r2911 107 107 108 108 ∀ MetaAssoc C₁, C₂, MetaClass M₁, M₂ 109 : C₁.catPair = C₂ ∧ C₁.catClass = M₁ ∧ C₂.catClass = M₂ 109 : C₁.catPair = C₂ ∧ C₁.assocCompanion 110 ∧ C₁.catClass = M₁ ∧ C₂.catClass = M₂ 110 111 → ( ∃ M₁.clsCats{C₂.catCompanion} 111 112 ∧ ∃ M₂.clsCats{C₁.catCompanion}
