I'm having trouble dropping classes in Mata when they have virtual functions. I've included an example below where I'm not able to drop a parent class, but in another situation I have been unable to drop a child class.
I'm wondering whether anyone else has run into this problem, whether it's a known issue, whether dropping is disallowed in this situation, etc.
I am using Stata/IC 13.1 on Windows 7.
Here is an example from the documentation (help m2_class##def_virtual). The contents of class_example.mata appear at the end of this message. Inside the file a call to drop the parent class leads to an error. By the time that call is reached any explicit references to the class have been dropped.
Just to be sure there are no references, I do mata: mata describe, see nothing else defined, try to drop again, and again get an error.
Here are the contents of class_example.mata:
[edited to use Nick Cox's suggestion regarding bold, below]
I'm wondering whether anyone else has run into this problem, whether it's a known issue, whether dropping is disallowed in this situation, etc.
I am using Stata/IC 13.1 on Windows 7.
Here is an example from the documentation (help m2_class##def_virtual). The contents of class_example.mata appear at the end of this message. Inside the file a call to drop the parent class leads to an error. By the time that call is reached any explicit references to the class have been dropped.
Code:
. mata: mata clear . run class_example.mata classdef animal() in use (nothing dropped)
Code:
. mata: mata describe # bytes type name and extent ------------------------------------------------------------------------------- 296 classdef scalar animal() 88 void ::poke() 88 void ::sound() ------------------------------------------------------------------------------- . mata: mata drop animal() classdef animal() in use (nothing dropped) r(310);
Here are the contents of class_example.mata:
Code:
mata class animal { virtual void sound() void poke() } void animal::sound() { "Squeak!" } void animal::poke() { sound() } class cow extends animal { virtual void sound() } void cow::sound() { "Moo!" } cow = cow() cow.poke() // clean up mata drop cow mata drop cow() mata drop animal() end
Comment