[Grace-core] How to Program in Grace

Andrew P. Black black at cs.pdx.edu
Wed Nov 21 13:16:59 PST 2012


In attempting to track down a compiler bug, I've realized that the code that I wrote and tested last summer no longer compiles.  Well, it's not legal Grace, so I supposed that I shouldn't complain.

I had created a number of objects like this:

def assertionTrait:Assertion = object {
    method assert(bb: Boolean)description(str) is public {
        if (! bb) 
        then {
            print "***** {str} ******"
            globalFailureCount := globalFailureCount + 1
        }        
    }

    method deny(bb: Boolean)description (str) is public {
        assert (! bb) description (str)
    }
        
    method assert(bb: Boolean) is public {
        assert (bb) description "***** Assertion failed! ******"
    }

    method deny(bb: Boolean) is public {
        assert (! bb)
    }

    method assertEquals(s1:Object, s2:Object) is public {
        assert (s1 == s2) description "\"{s1}\" should be \"{s2}\""
    }
}


whose raison d'être is to share the methods that they contain.   These objects play the role of Traits in Smalltalk, or Trait objects in Self, or abstract classes in Java.  Later, I would re-use this code:

object {
            inherits assertionTrait
            def tests = list.new
		…

That inherits clause is illegal by the current rules.  The compiler doesn't complain about it, but does complain that the object created does not have the type that I think it should have.

Now I don't know how to write this code in Grace.  "Copy and Paste inheritance" is not a good idea.  The best that I could come up with was

class assertion.trait -> Assertion {
    method assert(bb: Boolean)description(str) is public {
        if (! bb) 
        …

and then inheriting from the class constructor:

object {
            inherits assertion.trait
            def tests = list.new

But it gets worse!  I also had object constructers with multiple methods, which used to inherit some of those methods from super object constructors, while overriding one of them (the one that actually did the construction).  How should I write those?

	Andrew



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailhost.cecs.pdx.edu/mailman/private/grace-core/attachments/20121121/758ea93c/attachment.html>


More information about the Grace-core mailing list