This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: type declaration best practices?


I changed (in SVN) the Kawa reader so white space
are optional both before and after :: .
Thus you can write:

(define var1 ::int 12)

or:

(define var2::list '(3))

I did try changing the reader so that
  :: TYPE
would be read as
  ($coloncolon$ TYPE)
However, this turned out to be a lot of work.  It might make
sense if re-doing Kawa from scratch, but since we need to support
the old syntax, it was a lot easier to just tweak the reader.

Given that we're more-or-less stuck with :: what would be
the preferred type declaration syntax?  For variable declarations
I think I would recommend keeping the space before the colon,
but leaving it out after, as in:

(define var1 ::int 10)
(let ((var2 ::list (cons x y))) ...)

For function declarations, I'm dithering between:
(1)
(define (string-ref (str ::string) (k ::int)) ::char
  (invoke str 'charAt k))
(2)
(define (string-ref str ::string k ::int) ::char
  (invoke string 'charAt k))
(3)
(define (string-ref str::string k::int) ::char
  (invoke string 'charAt k))

(1) is more verbose, but it may be easier to read (for
humans) and it handles default values (for #!optional
parameters) better.

Comments?

So how would (future) type annotations fit in?  I think by
coming after the :: as in:
(define x ::(@NonNull)string (...))

[This is an advantage of having :: as just a plain symbol
- it makes it easier to add type annotations - at least
conceptually.]

Note above I'm talking about type annotations, as are likely
to be added to jdk7.  The Java5 declaration annotations would
go someplace else, possibly before the variable name, as in:
(define (@Deprecated) bar #!null)
Advantage of this is that it is matches Java, and that it
works with function definitions, as in:
(define (@Override) (foo ...) ...)
But this is to be decided later.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]