Working on a project where I want to keep the Mata library as consistent with the original library it is wrapping as consistently as possible and was wondering how to access classes that are initialized by methods within a class. For example:
Creates two classes with methods that are similar to what I am working with. When I try testing some stuff interactively I end up getting an error that I'm having difficulty understanding:
I was wondering if this is a place where I need to be using pointers or if there is some other technique that people tend to use more frequently to accomplish similar goals? Ideally, one would be able to do something like: (pseudo code loosely based on the examples above)
Code:
mata: mata clear class B { private string scalar mydatum public string scalar get() void init(), modifier() } void B::init(string scalar vnm, | string scalar arguments) { if (arguments != "") { this.mydatum = "var " + vnm + " = " + arguments } else { this.mydatum = vnm } } void B::modifier(string scalar content) { this.mydatum = this.get() + ".someContentMethod(" + content + ")" } string scalar B::get() { return(this.mydatum) } class A { private string scalar originalDatum public string scalar get() void init(), modifier() class B scalar newb() } void A::init(string scalar vnm, string scalar arguments) { this.originalDatum = "var " + vnm + " = " + arguments } void A::modifier(string scalar contents) { this.originalDatum = this.get() + ".originalMethod(" + contents + ")" } string scalar A::get() { return(this.originalDatum) } class B scalar A::newb(| string scalar v, string scalar a) { class B scalar newClassB newClassB = B() if (v != "" & a != "") { newClassB.init(v, a) } else if (v != "" & a == "") { newClassB.init(v) } else { newClassB.init(this.get()) } return(newClassB) } end
Code:
. mata ------------------------------------------------- mata (type end to exit) ----------------------------- : x = A() : x.init("thisvar", "theseContents") : x.get() var thisvar = theseContents : x.newb("newObject", "parameterArgument").modifier("anotherMethod").get() type mismatch: exp.exp: transmorphic found where struct expected r(3000); : x.newb("newObject", "parameterArgument").get() var newObject = parameterArgument : y = x.newb("newObject", "parameterArgument") type mismatch: transmorphic = class not allowed r(3000);
Code:
mata: x = A() x.init(`""myvar""', `""args""') x.newb(`""newVar""', `""moreArgs""').modifier("changeSomething").otherModifier("toSomethingElse").get()
Comment