How come Clojure didn't adopt the Kawa colon-syntax when calling out to Java?


#1

Warning: Syntax rant.

I don’t find Clojure’s (.method obj) and (.-field obj) syntax very pleasing. Is there any compelling reason that Kawa’s syntax (obj:method) and (obj:field) Java interop wasn’t adopted?


#2

(.method obj) seems more consistent with the (f obj) used for non-interop calls.


#3

Right, and it means that things like the threading operators (-> etc) work consistently. It’s a pain for completion though.


#4

Well, if one think of it in terms of generic functions I could agree, but when writing code in OO languages I tend to think in terms of Smalltalk message passing, in which case the receiver comes first. Racket also has a single-dispatch object system in which the receiver comes before the receiver. But yes, Clojure not being particularly OO-focused language I guess I need to reconsider.


#5

This makes a lot of sense, thank you. I sympathize with you regarding the completion. :wink:


#6

I think you get used to it.

Also, in case you didn’t know, you can use .. to make it receiver first.

(.. "1234" length)

Or ->

(-> "1234" .length)

Notice the difference though, .. also adds the . while -> only changes the order.

And, how does Kawa handle chaining? When methods have extra args?

(.. someObj (withName "John") (withAge 23))

For example?


#7

Good question! I’ll see if I can find out.