r/Clojure • • Mar 18 '21

Clojure - Keyword argument functions now also accept maps

https://clojure.org/news/2021/03/18/apis-serving-people-and-programs
125 Upvotes

44 comments sorted by

View all comments

21

u/vvvvalvalval Mar 18 '21

I'll still refrain from designing functions that way, and would encourage people to do the same.

Compared to keyword-varargs, an optional map argument costs at worst one more keystroke to invoke, and it's simply a more straightforward and regular behaviour to build on top of.

I suspect that most of the Clojure APIs out there which use keyword varargs did so by imitation of Python and just overlooked the alternative of using a map argument, or really had an unsound obsession with concision.

9

u/SimonGray Mar 18 '21

The great thing about this change is that people who feel like this can just call all those varargs functions using a map now.

12

u/vvvvalvalval Mar 18 '21 edited Mar 18 '21

I agree, it's great for calling legacy functions, but that doesn't mean it has eliminated all the downside of keyword varargs. Avoiding irregularity is better than gaining tools for dealing with it.

EDIT: really, people are downoting this? Reminder of the Reddiquette: "Please don't downvote an otherwise acceptable post because you don't personally like it." Why not write a rebuttal instead?

1

u/adamtait Mar 18 '21

I agree with what you’re saying but suspect that change was not made to Clojure core because of backwards compatibility. For that reason, I doubt it’ll ever be changed in Clojure core. This change likely suggests that there are some on the Core team who would have wished the keyword varargs feature to not have been included in the language originally.

20

u/alexdmiller Mar 18 '21

Actually, just the opposite, the core team wishes this new feature had been included originally to make using kwarg style functions more widely used and embraced.