[Grace-core] Considering Traits as Objects in Grace

James Noble kjx at ecs.vuw.ac.nz
Wed Mar 6 10:37:02 PST 2013


On 5/03/2013, at 23:19 PM, Michael Homer wrote:

>  I currently have an "is parent" annotation
> implemented (on def fields only), which gives essentially the
> single-delegation behaviour described.

so one thing I figured out was that we can try the delegation version using this - 
the following code can be pasted into a fresh minigrace, it works but has an error
that I'm not sure how to fix (because I'm not sure what Andrew meant)


print "start"

def myTrait = object {
    method create {
        print "myTrait.create"
        done}
    method initialize {
        print "myTrait.initialize"
        done}
    method new {
        print "myTrait.new"
        def instance = self.create
        instance.initialize
        return instance
    }
}

def myClass = object {
    def myParent is parent = myTrait
    method create {
        print "myClass.create"
        return object {
            def myNewObject = "foo"
        }
    }
}

myClass.new 


print "end"



More information about the Grace-core mailing list