This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: type declaration best practices?
* Per Bothner [2009-11-13 00:57+0100] writes:
>> (define (tagged-vector3f (tag symbol) (x float) (y float) (z float)) ::
>> pair
>> (cons tag (make javax.vecmath.Vector3f x y z)))
>
> Likewise not my preferred style - I think including the colons helps.
>
> But this is something I've been pondering, and perhaps a question
> for the list. In define and let you can just add the optional :: TYPE
> without having to add extra parentheses. I'm thinking a slight change,
> in removing a space, might make things more readable:
>
> (define (tagged-vector3f tag ::symbol x ::float y ::float z ::float)
> ::pair
> (cons tag (make javax.vecmath.Vector3f x y z)))
> (define xxx ::integer 123)
>
> Or perhaps allow leaving out the preceding space as well:
>
> (define (tagged-vector3f tag::symbol x::float y::float z::float)
> ::pair
> (cons tag (make javax.vecmath.Vector3f x y z)))
> (define xxx::integer 123)
>
> I think PLT allows something like that, except using a single colon
> - but that would conflict with colon notation, alas.
>
> Implementation becomes a little tricky: The easiest mechanism
> is to just define that there is a "delimiter" before and after
> double-colon - that would just be a reader change (which would
> be disabled in strict-R6RS-mode, if/when we provide that).
>
> Comments?
I think the double colons are ugly and get in the way of macros. Also,
if I were afraid of parens I wouldn't use Lisp in the first place.
I like how Goo [1] did it:
(df tagged-vector3f ((tag symbol) (x float) (y float) (z float) => pair)
... )
Note that the return type is folded into the arglist which is IMO cute
and also works nicely for functions with multiple return values.
Goo also offers | as infix option but something like var|type is always
translated to (var type) by the reader.
An example where those double colons didn't work was the DO macro in
kawa/lib/std_syntax.scm. For a long time it was only possible to give
the first variable a type with double colons. But with parens it was
possible to give all variables a type:
(do (((x int) 1 ...)
((y float) 1 ...))
...)
always worked beautifully. The new definition of DO which handles :: in
all places is long winded and complicated.
Helmut
[1] http://people.csail.mit.edu/jrb/goo/manual/goomanual.html