Or at least open an issue requesting this feature (and similar for Matrix, which is another Array alias). But I think you'll find this is a pretty simple contribution once you figure out the syntax and where to put the method definitions :-)
On Wednesday, February 4, 2015, Mauro <mauro...@runbox.com> wrote: > In 0.4, with call overloading, it would now be possible to have a > constructor Vector(Int,5) (this is not possible in 0.3). You could > submit a pull request to add that feature. > > On Wed, 2015-02-04 at 11:16, Kristoffer Carlsson <kcarlsso...@gmail.com > <javascript:;>> wrote: > > Ah, yes you are right about the Array{Int, 2} stuff. > > > > The reason I want to do this at all is because I have functions taking > > Vectors as arguments but then I have to create the vectors that I want to > > pass into the function using the Array command. It would somehow feel > more > > unified if I could create my Vectors with the Vector command and pass > them > > into my function that accepts a Vector. Vectors everywhere :) > > > > Thank you for your help. > > > > > > On Wednesday, February 4, 2015 at 11:08:55 AM UTC+1, Milan Bouchet-Valat > > wrote: > >> > >> Le mercredi 04 février 2015 à 02:00 -0800, Kristoffer Carlsson a écrit > : > >> > >> If you want to allocate an Array you can simply write: > >> > >> > >> > >> julia> Array(Int, 5, 1) > >> 10x1 Array{Int64,2}: > >> 2187293504 > >> 2151034912 > >> 2195818528 > >> 2147516504 > >> > >> > >> > >> Now, Vector is a short form for Array{T, 1}. I would then expect to be > >> able to allocate a vector using something like this: > >> > >> > >> > >> julia> Vector(Int, 5) > >> ERROR: MethodError: `convert` has no method matching > convert(::Type{Array{ > >> T,1}}, > >> ::Type{Int64}, ::Int64) > >> This may have arisen from a call to the constructor Array{T,1}(...), > >> since type > >> constructors fall back to convert methods in julia v0.4. > >> Closest candidates are: > >> convert{T}(::Type{Nullable{T}}, ::T) > >> convert{T}(::Type{T}, ::T) > >> convert{T}(::Type{FloatRange{T}}, ::FloatRange{T<:FloatingPoint}) > >> ... > >> > >> > >> > >> Could someone help me with the syntax? Do you have to use the Array > form > >> every time you want to initiate a Arrat{T,1} with a certain length? > >> > >> As you can see from the printed output, Array(Int, 5, 1) creates an > >> Array{Int, 2}, which is different from a Vector. If you want a Vector, > call > >> Array(Int, 5). I've often tried typing Vector(Int, 5) too, and wished it > >> existed, but as it would be redundant with Array(), I'm not sure it's a > >> good idea to add it. > >> > >> Regards > >> > >