Show
Ignore:
Timestamp:
05/10/05 02:16:17 (4 years ago)
Author:
mugwump
svk:copy_cache_prev:
4437
Message:

* explanatory essay in MetaAssoc?
* added missing clause on a Class.hs rule
* convert ∃ → ∀ in MetaClass?

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • ext/Perl-MetaClass/lib/Perl/MetaAssoc.pm

    r2905 r2911  
    77sub Perl::MetaAssoc::new(Str $class) returns Str is export { 
    88    ($class.instance_isa('Perl::MetaClass')) 
    9             || die "Class must be a Perl::MetaClass instance";    
     9            || die "Class must be a Perl::MetaClass instance"; 
    1010    my $id = make_instance("Perl::MetaAssoc", {  
    1111        'class'       => $class,   # Perl::MetaClass 
     
    1313        'range'       => [0, Inf], # Range 
    1414        '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 
    1818    }); 
    1919    return $id; 
    2020} 
    2121 
    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₁ 
    2824# (this is just bi-directional pairing of the two associations) 
    29 #  
     25# 
    3026# -- can't be composite both ways 
    31 #  
    32 # ∃ MetaAssoc C₁, C₂ : C₁.assocPair = C₂ ∧ C₁.assocIsComposite 
    33 #      → ¬(C₂.catIsComposite) 
    34 #  
     27# 
     28# 
    3529# -- 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  
    4533 
    4634 
     
    9684  use Perl::MetaAssoc; 
    9785 
     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 
    98107=head1 DESCRIPTION 
     108 
     109A Perl::MetaAssoc represents a fairly abstract concept.  Firstly, it 
     110is a class of the B<meta-model>, which is not C<Class.meta()> objects 
     111at all.  That distinction is explained at L<Perl::MetaClass>. 
     112 
     113This class is used to describe I<relationships> between two classes in 
     114the Class model.  For instance, a Class can have any number of defined 
     115methods, and each method can only belong to one class.  These two 
     116comments are frequently viewed as being seperate relationships, but in 
     117fact they are simply different ways of looking at the same 
     118relationship; that a method belongs to exactly one class (or package, 
     119or whatever). 
     120 
     121Each side of the relationship is identical to the other; so, in this 
     122metamodel, relationships are represented with I<two> objects - one for 
     123each side. 
     124 
     125There is a lot of implicit 'magic' assumed to be happening in the 
     126example.  This magic stems from rules such as the following; 
     127 
     128   ∀ MetaClass A, MetaAssoc C : A.clsAssoc ∋ C ↔ C.assocClass = A 
     129 
     130This is read as "For every MetaClass A and MetaAssoc C, such that 
     131A.clsAssoc contains C, it is automatically implied that C.assocClass 
     132is A". 
     133 
     134We 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 
     140However, this would be needless duplication of expressing the 
     141relationship; we want this all to happen automatically. 
     142 
     143This rule is almost identical: 
     144 
     145  ∀ MetaAssoc C₁, C₂ : C₁.assocPair = C₂ ↔ C₂.assocPair = C₁ 
     146 
     147Just by stating that the C<assocPair> for one of the C<MetaAssoc> 
     148objects is the other, we don't need to specify the reverse relation. 
     149 
     150Similarly, 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 
     162Then simply by specifying that the C<properties> MetaAssoc object's 
     163companion is called "class", this will mean that its pair MetaAssoc 
     164object's name within the "Property" clsAssocs collection is "class". 
     165It also implies that the pair MetaAssoc will have a C<companion> 
     166property of "properties". 
     167 
     168Finally, it is implied that the other side of the association cannot 
     169be composite; 
     170 
     171  ∀ MetaAssoc C₁, C₂ : C₁.assocPair = C₂ ∧ C₁.assocIsComposite 
     172     → ¬(C₂.catIsComposite) 
    99173 
    100174=head1 AUTHORS