[CLJ-976] Implement reader literal and print support for PersistentQueue data structure Created: 27/Apr/12 Updated: 06/Apr/13 |
|
| Status: | Open |
| Project: | Clojure |
| Component/s: | None |
| Affects Version/s: | Release 1.5 |
| Fix Version/s: | None |
| Type: | Enhancement | Priority: | Minor |
| Reporter: | Fogus | Assignee: | Fogus |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | data-structures, queue, reader, tagged-literals | ||
| Attachments: |
|
| 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. |
| Comments |
| Comment by Steve Miner [ 27/Apr/12 10:18 AM ] |
|
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. |
| Comment by Chas Emerick [ 27/Apr/12 10:19 AM ] |
|
The precedent of records seems relevant: => (defrecord A [b])
user.A
=> #user.A[(+ 4 5)]
#user.A{:b (+ 4 5)}
=> #user.A{:b (+ 4 5)}
#user.A{:b (+ 4 5)}
This continues to make sense, as otherwise queues would need to print with an extra (quote …) form around lists — which records neatly avoid: => (A. '(+ 4 5))
#user.A{:b (+ 4 5)}
Does this mean that a queue fn (analogous to vector, maybe) will also make an appearance? It'd be handy for HOF usage. |
| Comment by Fogus [ 27/Apr/12 11:00 AM ] |
|
Added a patch for the tagged literal support ONLY. This is only one part of the total solution. This provides the read-string and printing capability. I'd like more discussion around the eval side before I get dive into the compiler. |
| Comment by Paul Michael Bauer [ 27/Apr/12 6:45 PM ] |
|
In addition to Chas' observations on consistency with record literals, would eval in queue literals open up the same security hole as #=, needing to respect *read-eval*? |
| Comment by Fogus [ 04/May/12 1:14 PM ] |
|
Evalable queue literal support. |
| Comment by Andy Fingerhut [ 10/May/12 5:54 PM ] |
|
Neither of the patches CLJ-976-queue-literal-tagged-parse-support-only.diff dated Apr 27, 2012 nor CLJ-976-queue-literal-eval.diff dated May 4, 2012 apply cleanly to latest master as of May 10, 2012. |
| Comment by Fogus [ 11/May/12 10:15 AM ] |
|
Updated patch file to merge with latest master. |
| Comment by Fogus [ 20/Jul/12 1:14 PM ] |
|
New patch with support fixed for syntax-quote. |
| Comment by Stuart Sierra [ 17/Aug/12 12:41 PM ] |
|
Patch does not apply as of commit f5f4faf95051f794c9bfa0315e4457b600c84cef |
| Comment by Fogus [ 17/Aug/12 3:06 PM ] |
|
Weird. I was able to download the CLJ-976-queue-literal-eval-and-synquote.diff patch and apply it to HEAD as of just now (f5f4faf95051f794c9bfa0315e4457b600c84cef). There were whitespace warnings, but the patch applied, compiles and passes all tests. |
| Comment by Andy Fingerhut [ 17/Aug/12 7:29 PM ] |
|
With latest head I was able to successfully apply patch CLJ-976-queue-literal-eval-and-synquote.diff with this command: git am --keep-cr -s < CLJ-976-queue-literal-eval-and-synquote.diff with some warnings, but successfully applied. If I try it without the --keep-cr option, the patch fails to apply. I believe this is often a sign that either one of the files being patched, or the patch itself, contains CR/LF line endings, which some of the Clojure source files definitely do. The command above (with --keep-cr) is currently the one recommended for applying patches on page http://dev.clojure.org/display/design/JIRA+workflow in section "Screening Tickets". I added the suggested --keep-cr option after running across another patch that applied with the option, but not without it. |
| Comment by Andy Fingerhut [ 28/Aug/12 5:45 PM ] |
|
Presumptuously changing Approval from Incomplete back to Test, since the latest patch does apply cleanly if --keep-cr option is used. |
| Comment by Rich Hickey [ 08/Sep/12 6:48 AM ] |
|
this needs more time |
| Comment by Fogus [ 18/Sep/12 8:15 AM ] |
|
Rich, Do you mind providing a little more detail? I would be happy to make any changes if needed. However, if it's just a matter of its relationship to EDN and/or waiting until the next release then I am happy to wait. In either case, I'd like to complete this or push it to the back of my mind. Thanks. |
| Comment by Andy Fingerhut [ 05/Oct/12 7:49 AM ] |
|
clj-976-queue-literal-eval-and-synquote-patch-v2.txt dated Oct 5 2012 is identical to Fogus's patch CLJ-976-queue-literal-eval-and-synquote.diff dated Jul 20 2012. It simply removes one line addition to clojure.iml that Rich has since added in a different commit, so that this patch now applies cleanly to latest master. |
| Comment by Andy Fingerhut [ 16/Oct/12 12:20 PM ] |
|
clj-976-queue-literal-eval-and-synquote-patch-v3.txt dated oct 16 2012 is identical to Fogus's patch CLJ-976-queue-literal-eval-and-synquote.diff dated Jul 20 2012. It simply removes one line addition to clojure.iml that Rich has since added in a different commit, so that this patch now applies cleanly to latest master. |
| Comment by Andy Fingerhut [ 20/Oct/12 12:26 PM ] |
|
Fogus, with the recent commit of a patch for |
| Comment by Steve Miner [ 06/Apr/13 8:07 AM ] |
|
Related to CLJ-1078. |
[CLJ-326] add :as-of option to refer Created: 30/Apr/10 Updated: 24/Aug/10 |
|
| Status: | In Progress |
| Project: | Clojure |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | Approved Backlog |
| Type: | Enhancement | ||
| Reporter: | Anonymous | Assignee: | Christophe Grand |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Approval: | Test |
| Description |
|
Discussed here: http://groups.google.com/group/clojure-dev/msg/74af612909dcbe56 :as-of allows library authors to specify a known subset of vars to refer from clojure (or any other library which would use :added metadata). (ns foo (:refer-clojure :as-of "1.1")) is equivalent to (ns foo (:refer-clojure :only [public-documented-vars-which-already-existed-in-1.1])) |
| Comments |
| Comment by Assembla Importer [ 24/Aug/10 10:19 AM ] |
|
Converted from http://www.assembla.com/spaces/clojure/tickets/326 |
| Comment by Assembla Importer [ 24/Aug/10 10:19 AM ] |
|
cgrand said: [file:a8SumUvcOr37SmeJe5cbLA]: requires application of #325 |
| Comment by Assembla Importer [ 24/Aug/10 10:19 AM ] |
|
richhickey said: Do we still need this? |