View · Search · Index
No registered users in community xowiki
in last 10 minutes

[Xotcl] Unforwarding object method

From: Scott Gargash <scottg_at_atc.creative.com>
Date: Tue, 7 Mar 2006 14:43:17 -0700

Hello,

I've just started looking at XOTcl over the last couple days, and so far I like it a lot. Since I'm
still learning, I assume I've overlooked something in the documentation, but I can't find how to
remove a forwarded method from an object. It seems that all I can do is add a forwarded method, but
once installed, I can never unforward a method. Is this true?

Here's an (simplified) example of what I'm trying to do:

Object a
a proc foo {args} {
  puts "a: [self] foo"
}

Object b
b set overrides {}
b proc foo {obj} {
  puts "b: [self] foo"
  if {-1 == [lsearch [my set overrides] $obj]} {
    puts "b is overriding $obj foo"
    $obj forward foo [self] overridefoo $obj
  }
}

b proc overridefoo {obj args} {
  if {$args eq "done"} {
    puts "stop forwarding foo for $obj"
    set idx [lsearch -exact [my set overrides] $obj]
    my set overrides [lreplace [my set overrides] $idx $idx]
    # This doesn't work! What should be here?
    $obj forward foo {}
    puts "redispatching foo to native $obj foo"
    $obj foo $args
  } else {
    puts "using override of foo on $obj $args"
  }
}
a foo 123
b foo a
a foo 234
a foo done

----------

>From what I gather, the intended mechanism for doing this is to use a mixin to intercept the foo
method, but a already has a foo method that's being used for other purposes. I suppose I could
dynamically create another object (or would it have to be a class?) to use as a mixin, but that
seems unnecessarily complex. Is there a better way to accomplish what I'm trying to do?


BTW, I'm running xotcl 1.3.6. If I run the above sample 3 times, I get the following error:

procedure "foo" has formal parameter "::xotcl::initProcNS" that is not a simple name

and the interpreter crashes on the next command. That's probably a bug, but since I'm not at the
latest release, I don't know if it's something that's been fixed already.

Thanks.

      Scott




Notice
The information in this message is confidential and may be legally privileged. It is intended
solely for the addressee. Access to this message by anyone else is unauthorized. If you are not
the intended recipient, any disclosure, copying or distribution of the message, or any action
taken by you in reliance on it, is prohibited and may be unlawful. If you have received this
message in error, please delete it and contact the sender immediately. Thank you.