Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Clojure by

rename-keys is hard to find when it lives in the clojure.set namespace, because it acts on maps and not sets. To my eyes set/rename-keys also looks strange when reading code, but this is the preferred way to bring in the clojure.set namespace.

This is one of the minor warts I'd like to see fixed in clojure 2.0.

9 Answers

+2 votes
by

Comment made by: marc

We will not delete/move existing vars as this would break existing programs.

This issue can be addressed without deletion as per Gordon's suggestion:

A new var could be added to {{clojure.core}} named {{clojure.core/rename-keys}}. Then the {{rename-keys}} var in {{clojure.set}} can be defined as:

(def rename-keys clojure.core/rename-keys)

0 votes
by

Comment made by: gordonsyme

It's not just {{rename-keys}}, there are a few fns in {{clojure.set}} that don't make sense being there, at first glance anyway.

It certainly harms discoverability of these fns.

I've come across at least one re-implementation of {{rename-keys}} and {{map-invert}} during my day job because the author didn't know these fns exist.

I'd argue for breaking the relational and map fns out of {{clojure.set}} into their own namespaces and deffing some vars in {{clojure.set}} for backwards compatibility.
Those compatibility vars could be deleted in 1.10.

I'm happy to do this (or another approach) but would like some buy in on the approach from the core team first.

0 votes
by

Comment made by: bronsa

I think this is very, very unlikely to ever happen

0 votes
by

Comment made by: alexmiller

We will not delete/move existing vars as this would break existing programs.

0 votes
by

Comment made by: alexmiller

I am aware of that, which is why I did not close the issue. I was just stating one possible resolution that is off the table.

0 votes
by

Comment made by: bozhidar

Out of curiosity - does anyone know how/why those functions ended up in the clojure.set namespace?

P.S. If someone decides to alias things between namespaces I'd suggest creating a clojure.map ns over pouring more stuff into core.

0 votes
by

Comment made by: hiredman

a more accurate name for clojure.set based on its contents would be something like clojure.relational-algebra, where it defines something like relational algebra over sets of maps instead of over sets of tuples. A common operation in that case is renaming keys in maps (similar to using AS in a sql query). Which explains why rename-keys is in clojure.set

0 votes
by

Comment made by: jafingerhut

Bozhidar - only a guess, not knowledge. Relations are sets of records/tuples, so to me it makes some sense that functions on relations are in clojure.set. rename-keys is probably there because it is used by two of the functions operating on relations.

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-1820 (reported by alex+import)
...