On Tue, May 17, 2016 at 8:41 AM, Manor Askenazi
<[email protected]> wrote:
> Let's say I want to represent the result of the following, but using literal
> syntax:
>
> v=Vector{FloatRange{Float64}}(3)
> v[1] = 1.0:0.5:2.0
> v[2] = 3.0:0.1:4.0
> v[3] = 5.0:0.2:6.0

This constructs a uninitialized array.

>
> In other words, I want to generate this:
>
>> 3-element Array{FloatRange{Float64},1}:
>>  1.0:0.5:2.0
>>  3.0:0.1:4.0
>>  5.0:0.2:6.0
>
>
> What is the equivalent way to write this using literal syntax?
>
> This doesn't work:
>
>     Vector{FloatRange{Float64}}([1.0:0.5:2.0, 3.0:0.1:4.0, 5.0:0.2:6.0])

And this is not the right syntax for constructing an initialized array

>
> Because:
>
>     [1.0:0.5:2.0, 3.0:0.1:4.0, 5.0:0.2:6.0]
>
> Just turns into a 20-element Array{Float64,1} !!!

This is deprecated on 0.4 and returns an Vector{FloatRange{Float64}} on 0.5

>
> Which is confusing because this works fine:
>
>    Vector{ASCIIString}(["Consistent", "Syntax", "Matters"])
>
> And so does this:
>
>     Vector{Float64}([0.1, 0.2, 0.3])

Both of these are incorrect usage, the `Vector{...}` is either a no-op
or is doing a unnecessary conversion.

The correct syntax for creating an initialized array of a particular type is

`FloatRange{Float64}[1.0:2.0, 2.0:3.0]`

which I believe works on both 0.4 and 0.5.

>
> I'm sure there is a trivial way to do this, but I'm missing the obvious,
> obviously :-)
>

Reply via email to