Clojure

Move rename-keys from clojure.set to clojure.core

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Trivial Trivial
  • Resolution: Unresolved
  • Affects Version/s: Release 1.8
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

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.

Activity

Hide
Gordon Syme added a comment -

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.

Show
Gordon Syme added a comment - 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.
Hide
Nicola Mometto added a comment -

I think this is very, very unlikely to ever happen

Show
Nicola Mometto added a comment - I think this is very, very unlikely to ever happen
Hide
Alex Miller added a comment -

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

Show
Alex Miller added a comment - We will not delete/move existing vars as this would break existing programs.
Hide
Marc O'Morain added a comment -

> 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)
Show
Marc O'Morain added a comment - > 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)
Hide
Alex Miller added a comment -

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.

Show
Alex Miller added a comment - 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.
Hide
Bozhidar Batsov added a comment -

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.

Show
Bozhidar Batsov added a comment - 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.
Hide
Kevin Downey added a comment - - edited

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

Show
Kevin Downey added a comment - - edited 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
Hide
Andy Fingerhut added a comment -

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.

Show
Andy Fingerhut added a comment - 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.

People

Vote (7)
Watch (2)

Dates

  • Created:
    Updated: