[Xotcl] abstract methods

Uwe Zdun uwe.zdun at wu-wien.ac.at
Wed Jul 13 11:14:19 CEST 2005


Hi Koen,

it seems you've found a bug. The Method in predefined.xotcl should 
probably look like this:

::xotcl::Object instproc abstract {methtype methname arglist} {
 if {$methtype  != "proc" && $methtype != "instproc"} {
   error "invalid method type '$methtype', \
   must be either 'proc' or 'instproc'."
 }
 ::xotcl::my $methtype $methname $arglist "
   if {\[::xotcl::self callingproc\] == \[::xotcl::self proc\] &&
   \[::xotcl::self callingobject\] == \[::xotcl::self\]} {
     ::xotcl::next
   } else {
     error \"Abstract method $methname $arglist called\"
   }
 "
}

you can simply put this correction (which should also go into the next 
release) into the file and re-compile,
or if you do not want to recompile, overwrite the abstract method before 
running your program.

Uwe

Koen Danckaert wrote:

> Hello,
>
> The XOTcl manual says that an abstract method produces an error if it 
> is called directly. It seems that this is not always the case. E.g., 
> in the following example there is no error:
>
> Class C
> C abstract instproc a {}
> C instproc b {} {my a}
>
> C test
> test b
>
>
>> From an earlier discussion on the mailing list I found that 
>> predefined.xotcl contains the following code to avoid errors when an 
>> abstract method is invoked by "next":
>
>
> Object instproc abstract {methtype methname arglist} {
>  if {$methtype  != "proc" && $methtype != "instproc"} {
>    error "invalid method type '$methtype', \
>     must be either 'proc' or 'instproc'."
>  }
>  [self] $methtype $methname $arglist "
>    if {\[self callingproc\] != \[self proc\] &&     \[self 
> callingobject\] != \[self\]} {
>      error \"Abstract method $methname $arglist called\"
>    }
>  "
> }
>
> I guess the test should be "||" instead of "&&" ?
> But then, it doesn't do the right thing either, because callingproc is 
> empty in case of an invocation by "next".
>
>
> Regards,
> Koen Danckaert
> _______________________________________________
> Xotcl mailing list
> Xotcl at alice.wu-wien.ac.at
> http://alice.wu-wien.ac.at/mailman/listinfo/xotcl


-- 
Uwe Zdun
Department of Information Systems, Vienna University of Economics
Phone: +43 1 313 36 4796, Fax: +43 1 313 36 746
zdun at acm.org, uwe.zdun at wu-wien.ac.at



More information about the Xotcl mailing list