[Xotcl] Help with Filters. Resubmission.

Uwe Zdun uwe.zdun@uni-essen.de
Thu, 20 Dec 2001 18:08:11 +0100


My first explanation for this behavior from Monday was wrong ... 
sorry for that. 
In fact, the filter would filter maa ... if it is called directly (try
  
  a maa

at the end of the program.) The reason why it is not filtered is that an 
active filter does not filter calls issued by itself ... a filter is active 
in its pre- and post part, but not during next, and only for the current 
object. That is, if the filter does call a method on the same object, this 
method call will not be filtered by that filter. If there wouldn't be such a 
protection, there would nearly always be endless loops during filter calls 
that call other methods. (Because the called filter would then issue another 
call to be filtered and so on and so forth). A solution for the problem below 
would be to provide two filters that do not mutually exclude each other, like:

A instproc af args {
  set method [self calledproc]
  if {[[self] exists delegate]} {
    set del [[self] set delegate]
    if {$method != "ma"} {
      return [eval $del $method $args]
    } 
  }
  next
}
A instproc bf args {
  set method [self calledproc]
  if {[[self] exists delegate]} {
    set del [[self] set delegate]
    if {$method == "maa"} {
      return [eval $del mbb]
    }
  }
  next
}

A instfilter {af bf}


--uwe


> > Can anyone assist me in explaining what is happening here?
> > ------------------------------------------------------------
> > #Code: Win 98 version 0.91; got same problem with ver 0.85 3 months ago.
> >
> > Class A  -parameter {delegate}
> >
> > A instproc af args {
> >   set method [self calledproc]
> >   if {[[self] exists delegate]} {
> >     set del [[self] set delegate]
> >     if {$method == "maa"} {
> >       return [eval $del mbb]
> >     }
> >     if {$method != "ma"} {
> >       return [eval $del $method $args]
> >     }
> >   }
> >   next
> > }
> >
> > A instfilter {af}
> >
> > A instproc ma args {
> >   puts "method ma of A"
> > }
> >
> >
> > Class B
> > B instproc bf args {
> >   set sender [self callingobject]
> >   set method [self calledproc]
> >   puts "method is: $method"
> >   if {$method == "mb"} {
> >
> >     return [eval $sender maa]
> >   }
> >   next
> > }
> >
> > B instfilter bf
> >
> > B instproc mb args {
> >   puts "method mb of B"
> > }
> >
> > B instproc mbb args {
> >   puts "method mbb of B"
> > }
> >
> > B b
> > A a
> > a delegate b
> > #a ma ; #works ok
> > a mb
> >
> >
> >
> > _______________________________________________
> > Xotcl mailing list  -  Xotcl@alice.wu-wien.ac.at
> > http://alice.wu-wien.ac.at/mailman/listinfo/xotcl

-- 
Uwe Zdun
Institute for Computer Science, University of Essen
Phone: +49 201 81 00 332, Fax: +49 201 81 00 398
zdun@{xotcl,computer,acm}.org, uwe.zdun@uni-essen.de