Details
-
Type:
Enhancement
-
Status:
Open
-
Priority:
Minor
-
Resolution: Unresolved
-
Affects Version/s: Release 1.5
-
Fix Version/s: None
-
Component/s: None
-
Labels:
-
Patch:Code and Test
-
Approval:Test
Description
Clojure's PersistentQueue structure has been in the language for quite some time now and has found its way into a fair share of codebases. However, the creation of queues is a two step operation often of the form:
(conj clojure.lang.PersistentQueue/EMPTY :a :b :c) ;=> #<PersistentQueue clojure.lang.PersistentQueue@78d5f6bc>
A better experience might be the following:
#queue [:a :b :c] ;=> #queue [:a :b :c] (pop #queue [:a :b :c]) ;=> #queue [:b :c]
This syntax is proposed and discussed in the Clojure-dev group at https://groups.google.com/forum/?fromgroups#!topic/clojure-dev/GQqus5Wycno
Open question: Should the queue literal's arguments eval? The implications of this are illustrated below:
;; non-eval case #queue [1 2 (+ 1 2)] ;=> #queue [1 2 (+ 1 2)] ;; eval case #queue [1 2 (+ 1 2)] ;=> #queue [1 2 3]
The answer to this open question will determine the implementation.
I think the non-eval behavior would be consistent with the other reader literals in Clojure 1.4. It's definitely better for interop where some other language implementation could be expected to handle a few literal representations, but not the evaluation of Clojure expressions. Use a regular function if the args need evaluation.