[CLJ-342] Enhance (vector-of) to populate vector Created: 05/May/10 Updated: 20/Mar/11 Resolved: 20/Mar/11 |
|
| Status: | Closed |
| Project: | Clojure |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | Approved Backlog |
| Type: | Enhancement | Priority: | Minor |
| Reporter: | Assembla Importer | Assignee: | Daniel Solano Gómez |
| Resolution: | Completed | Votes: | 1 |
| Labels: | None | ||
| Attachments: |
|
| Approval: | Ok |
| Waiting On: | Stuart Halloway |
| Description |
|
As discussed on clojure-dev at <http://groups.google.com/group/clojure-dev/browse_thread/thread/97137884bb33f8ee>, I would like to enhance (vector-of) so that it can create a populated vector. There are two ways to do this: 1. Like vector, take an arbitrary number of arguments used to populate the array. |
| Comments |
| Comment by Assembla Importer [ 28/Sep/10 8:57 AM ] |
|
Converted from http://www.assembla.com/spaces/clojure/tickets/342 |
| Comment by Assembla Importer [ 28/Sep/10 8:57 AM ] |
|
dsg said: [file:ciVMWWwl8r35ypeJe5cbLr] |
| Comment by Assembla Importer [ 28/Sep/10 8:57 AM ] |
|
dsg said: I have attached a patch that implements the proposed enhancement. I am fairly certain it is not the absolutely highest performance implementation. I have not taken a lot of time to thoroughly study the code, but I think there is probably a way to create the initial array and pass it as an argument to the constructor, which would avoid a lot of the cons calls. Nonetheless, I think it is important enough to provide convenience of the interface. The implementation can always be changed later. |
| Comment by Assembla Importer [ 28/Sep/10 8:57 AM ] |
|
richhickey said: You can't have it both ways. vector-of should be like vector, I think. |
| Comment by Daniel Solano Gómez [ 25/Feb/11 4:29 PM ] |
|
I have updated my patch to reflect Rich's recommendation. vector-of now behaves similarly to vector. Includes tests. |
| Comment by Rich Hickey [ 10/Mar/11 11:45 AM ] |
|
For the 1,2,3 cases it's better to create an array of that size and .aset am into it, please. & rest case could bootstrap with 3-arg call as well. Thanks. |
| Comment by Daniel Solano Gómez [ 10/Mar/11 2:02 PM ] |
|
Updated patch to reflect Rich's suggestions. |