[Grace-core] Type declarations in Grace

Kim Bruce kim at cs.pomona.edu
Tue Jun 7 17:17:46 PDT 2011


Type declarations of the form

            type Pt{ … }

would be fine.  The only reason for suggesting

            interface Pt{…}

was because I thought we might want to have named function/closure types.  If there is no interest in that, then stick with type.

Types of variables as shown through interfaces:

The look of

x:=(v: T) -> Unit

as a declaration is pretty ugly.  There is a precedent of writing them in terms of properties in ObjectiveC (which picks up its OO syntax from Smalltalk).  Properties can be either readonly or readwrite.  Either way, they generate methods as follows:

If we declare

@property int year 

which defaults to readwrite, then methods year() and setYear(int) are generated automatically, as well as “dotted” short-cuts for each so one can write:

            o.year                        // in place of [o year]

            o.year = 2009         // in place of [o setYear: 2009]

While I’m somewhat sympathetic to having both forms, we are going for single choices, so I would likely prefer the syntax I suggested:

            year: Int

or

            year: Int <writeonly>

             year: Int <readwrite>

As a second choice, I’d prefer the setYear syntax, i.e.,

o.setYear(Number) -> Unit

used as

            o.setYear(2009)

understanding the issues with the change in capitalization.  I could also live with the year:= form if necessary, but it does make me cringe a bit.

(Again, keep in mind we are selling dogfood.  If instructors cringe that may be a problem even if students accept it!)

Kim


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


More information about the Grace-core mailing list