Clojure

Enhance (vector-of) to populate vector

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: Backlog
  • Component/s: None
  • Labels:
    None
  • Approval:
    Ok

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.
2. Like vec, take a collection and use it to populate the array.

  1. updated-enhance-vector-of.patch
    10/Mar/11 2:02 PM
    4 kB
    Daniel Solano Gómez
  2. enhance-vector-of.patch
    25/Feb/11 4:29 PM
    4 kB
    Daniel Solano Gómez

Activity

Hide
Assembla Importer added a comment -
Show
Assembla Importer added a comment - dsg said: [file:ciVMWWwl8r35ypeJe5cbLr]
Hide
Assembla Importer added a comment -

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.

Show
Assembla Importer added a comment - 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.
Hide
Assembla Importer added a comment -

richhickey said: You can't have it both ways. vector-of should be like vector, I think.

Show
Assembla Importer added a comment - richhickey said: You can't have it both ways. vector-of should be like vector, I think.
Hide
Daniel Solano Gómez added a comment -

I have updated my patch to reflect Rich's recommendation. vector-of now behaves similarly to vector.

Includes tests.

Show
Daniel Solano Gómez added a comment - I have updated my patch to reflect Rich's recommendation. vector-of now behaves similarly to vector. Includes tests.
Hide
Rich Hickey added a comment -

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.

Show
Rich Hickey added a comment - 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.
Hide
Daniel Solano Gómez added a comment -

Updated patch to reflect Rich's suggestions.

Show
Daniel Solano Gómez added a comment - Updated patch to reflect Rich's suggestions.

People

Vote (1)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: