From: Eric Mahurin Date: 2005-10-21T21:31:27+09:00 Subject: Re: [RCR] Cut-based AOP --- Daniel Schierbeck wrote: > Trans wrote: > > Daniel Schierbeck wrote: > > > >>+1 > >> > >>I only have one concern: I think the syntax is kinda weird. > It resembles > >>the class definition syntax, but I can't see why it should. > When you > >>write "class A < B" you're saying "class A inherits from > class B" or > >>"class A is affected by class B". If we apply the same to > "cut A < B", > >>it would be "cut A is affected by class B", which isn't the > case. Why > >>not use "cut A > B", "cut A affects class C". The singleton > syntax could > >>be like this "cut >> obj". > > > > > > Your .16 Yen is appreciated :) In fact we have discussed > similar > > notation: > > > > class A > Ac > > # advice > > end > > > > We decided against, mainly because it looks too much like > normal > > subclassing. though it is certaintly a possibility. > > > > How I say 'cut Ac < A' is "cut Ac cuts A.", though I > normally drop the > > first 'cut', "Ac cuts A". > > > > T. > > > > I just don't think the lesser than character should be used > when it > already has a certain meaning. I think the cut keyword is a > good idea, > but the < should be a >. Again, that's just my opinion ;) > > cut A > B; end > cut >> obj; end I don't like the cut syntax either. It doesn't seem to describe what it is doing very well. But, I don't think the above is a good solution either. To me, making a cut into a class is analogous to reopening a class. The difference is that super and superclass refer to the original class (or another cut in between) for cut and the parent class when simply reopening a class. Here is what I mean: class A def foo;"A";end end class B1 < A def foo;"B";end end class B2 < A def foo;"B";end end b1 = B1.new b1.foo # => "B" b2 = B2.new b2.foo # => "B" # super : A.instance_method(:foo).bind(self).call class B1 def foo "[" + super + "]" end end b1.foo # => "[A]" # modifies B2, inserting a cut in the inheritance chain # super : B2.instance_method(:foo).bind(self).call cut B2cut < B2 def foo "[" + super + "]" end end b2.foo # => "[B]" # super : B1.instance_method(:foo).bind(self).call class < "{[A]}" # super : B2.instance_method(:foo).bind(self).call b2_meta_class = class <" end self end b2.foo # => "<[B]>" # super : b2_meta_class.instance_method(:foo).bind(self).call cut < "{<[B]>}" The syntax is not consistent: class B meta-class of b ------- --------------- reopen class B ... end class <