Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection (Set) literal syntax should only be used with compile time constants #27

Closed
sw1nn opened this issue Jan 7, 2013 · 1 comment

Comments

@sw1nn
Copy link

sw1nn commented Jan 7, 2013

The Collections section should elaborate on when set literal syntax is not appropriate, i.e. when the values in the set are not compile time constants.

There's been recent discussion on this on the Clojure ML[1] and it's spawned a wiki page[2] The consensus is (AFAICT) that if there's a possibility of duplicate values the constructor functions are preferred over literal syntax. There's further discussion on whether duplicates are appropriate in literals, but I don't think that's worth adding here.

I propose adding the following

  • Only use set literal notation when set values are compile-time constants
; good
(hash-set (func1) (func2))

; bad, will throw exception if (func1) == (func2)  at runtime.
#{(func1) (func2)}

[1] https://groups.google.com/forum/?fromgroups=#!topic/clojure/AG667ACBd3I
[2] http://dev.clojure.org/display/design/Allow+duplicate+map+keys+and+set+elements

@bbatsov
Copy link
Owner

bbatsov commented Jan 8, 2013

Great suggestion. I'd suggest expanding the rule and it's example a bit and sending a PR.

@bbatsov bbatsov closed this as completed Jan 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants