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

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?

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

1 Like

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

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.

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

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?


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

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.