To solve the practical problem, you don't need the splicing operator there:
~~~
julia> [[1, 2], 3, 4]
4-element Array{Int64,1}:
1
2
3
4
julia> x = [1,2]
2-element Array{Int64,1}:
1
2
julia> [x,3,4]
4-element Array{Int64,1}:
1
2
3
4
~~~
The behavior does seem very strange to me too. It looks like it's caused by
some change in structure:
This is the example you gave:
~~~
julia> [[1, 2]... 3 4]
1x4 Array{Int64,2}:
1 2 3 4
julia> :([[1, 2]... 3 4])
:($(Expr(:hcat, :([1,2]...), 3, 4)))
julia> eval(ans)
ERROR: unsupported or misplaced expression ...
~~~
If we make the same hcat call directly, it works, but the expr has a
different structure:
~~~
julia> hcat([1,2]...,3,4)
1x4 Array{Int64,2}:
1 2 3 4
julia> :(hcat([1,2]...,3,4))
:(hcat([1,2]...,3,4))
julia> eval(ans)
1x4 Array{Int64,2}:
1 2 3 4
~~~
Notice that the [1,2]... part prints out differently than in the Expr above.
Trying to recreate the [1,2]... Expr:
~~~
julia> :([1,2]...) #this version has a comma in it, which the first version
didn't.
:([1,2]...,)
julia> :([1,2]...).head
:tuple
julia> :([1,2]...).args
1-element Array{Any,1}:
:([1,2]...)
julia> :([1,2]...).args[1] #this looks like the part that caused the error
above
:([1,2]...)
julia> :([1,2]...).args[1].head
:...
julia> eval(:([1,2]...).args[1])
ERROR: unsupported or misplaced expression ...
~~~
This error seems to be cause by evaluating a `...` without appropriate
context.
I was going to say that the splicing operator is supposed to only be on the
last argument to a function, but that's only relevant to defining Varargs
functions, not splatting things into calls.
~~~
julia> +((1,)...,2)
3
julia> :(+((1,)...,2))
:(+((1,)...,2))
julia> eval(:(+((1,)...,2)))
3
~~~
This seems like a bug to me. I expect you should open an issue on github,
because either neither or both of `[[1,2]... 3 4]` and `eval(:([[1,2]... 3
4]))` should work.
-- Leah
On Tue, Jan 28, 2014 at 11:55 PM, Sam L <[email protected]> wrote:
> Hi everyone,
>
> When I evaluate this expression in the REPL, things work:
>
> julia> [[1, 2]... 3 4]
> 1x4 Array{Int64,2}:
> 1 2 3 4
>
> However, if I try to assign the result to a variable, I get an error:
>
> julia> row = [[1, 2]... 3 4]
> ERROR: unsupported or misplaced expression ...
>
> Same with evaluating the quoted expression:
>
> julia> eval(:( [[1, 2]... 3 4]))
> ERROR: unsupported or misplaced expression ...
>
> For what I was doing, I ended up not needing expressions like the above,
> but I'm curious as to what went wrong.
>
> Anybody know what's going on here?
>
> Thanks!
> Sam
>