Clojure

Strip leading colons when creating keywords from single strings

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: Backlog
  • Component/s: None
  • Labels:
    None

Description

This seems unfortunate:

=> (-> :foo str keyword)
::foo

Symbols are far saner in this regard:

=> (-> 'foo str symbol)
foo

Simply stripping leading colons from strings prior to turning them into keywords should suffice. The 2-arity Keyword.intern method and clojure.core/keyword fn should be left intact, so as to provide an escape hatch for those that really do need colon-prefixed keywords.

Activity

Hide
Assembla Importer added a comment -

cemerick said: [file:bKmJCu2_Wr36meeJe5cbLA]

Show
Assembla Importer added a comment - cemerick said: [file:bKmJCu2_Wr36meeJe5cbLA]
Hide
Stuart Halloway added a comment -

I am uncomfortable with this. If I say (keyword "::foo"), what am I asking for? I almost wonder if this should throw an exception.

Show
Stuart Halloway added a comment - I am uncomfortable with this. If I say (keyword "::foo"), what am I asking for? I almost wonder if this should throw an exception.
Hide
Rich Hickey added a comment -

I think (keyword "::foo") (and any more leading colons) should fail, and this patch should only strip one colon.

Show
Rich Hickey added a comment - I think (keyword "::foo") (and any more leading colons) should fail, and this patch should only strip one colon.
Chas Emerick made changes -
Field Original Value New Value
Assignee Chas Emerick [ cemerick ]
Hide
Chas Emerick added a comment -

Updated patch forthcoming.

Show
Chas Emerick added a comment - Updated patch forthcoming.
Hide
Chas Emerick added a comment -

After thinking about this for a while, I've now reversed my position, and am in favor or retaining the current functionality. Thanks for the pushback.

As for throwing exceptions on colon-prefixed, un-namespaced keywords, I'm not certain that that's a good idea. People use keywords to hold all sorts of data, use them as map keys and lookup fns, etc.

Show
Chas Emerick added a comment - After thinking about this for a while, I've now reversed my position, and am in favor or retaining the current functionality. Thanks for the pushback. As for throwing exceptions on colon-prefixed, un-namespaced keywords, I'm not certain that that's a good idea. People use keywords to hold all sorts of data, use them as map keys and lookup fns, etc.
Chas Emerick made changes -
Status In Progress [ 3 ] Closed [ 6 ]
Approval Test
Resolution Declined [ 2 ]

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: