Re: [julia-users] A[]: Accessing array with empty index

2014-06-01 Thread Carlos Becker
I see now. I thought 0-dimensional arrays could not contain any element at
all.

For consistency, wouldn't it be better to thrown an error when myArray[] is
used for non-zero-dimensional arrays?
Looks like a difficult to find typo.


--
Carlos


On Fri, May 30, 2014 at 11:45 PM, Steven G. Johnson stevenj@gmail.com
wrote:



 On Friday, May 30, 2014 5:19:35 PM UTC-4, Carlos Becker wrote:

 HI Jacob,

 I get that, but which is the reasoning behind myArray[] ?
 why should it return a ref to the 1st element?


 Because you can have a 0-dimensional array, and a 0-dimensional array
 contains exactly 1 element (the empty product of the dimensions).



[julia-users] A[]: Accessing array with empty index

2014-05-30 Thread Carlos Becker
My apologies if this is something that was addressed before, I didn't find 
it.

Why does myArray[] return the first element of the array? is there a 
reasoning behind it or is it an 'unexpected language feature'?
For example:

a = [1,2,3,4]
a[]   = returns 1


Thanks.


Re: [julia-users] A[]: Accessing array with empty index

2014-05-30 Thread Jacob Quinn
a[] is rewritten as `getindex(a)`, which has a definition in array.jl#244

getindex(a::Array) = arrayref(a,1)

-Jacob


On Fri, May 30, 2014 at 5:05 PM, Carlos Becker carlosbec...@gmail.com
wrote:

 My apologies if this is something that was addressed before, I didn't find
 it.

 Why does myArray[] return the first element of the array? is there a
 reasoning behind it or is it an 'unexpected language feature'?
 For example:

 a = [1,2,3,4]
 a[]   = returns 1


 Thanks.



Re: [julia-users] A[]: Accessing array with empty index

2014-05-30 Thread Carlos Becker
HI Jacob,

I get that, but which is the reasoning behind myArray[] ?
why should it return a ref to the 1st element?




--
Carlos


On Fri, May 30, 2014 at 11:09 PM, Jacob Quinn quinn.jac...@gmail.com
wrote:

 a[] is rewritten as `getindex(a)`, which has a definition in array.jl#244

 getindex(a::Array) = arrayref(a,1)

 -Jacob


 On Fri, May 30, 2014 at 5:05 PM, Carlos Becker carlosbec...@gmail.com
 wrote:

 My apologies if this is something that was addressed before, I didn't
 find it.

 Why does myArray[] return the first element of the array? is there a
 reasoning behind it or is it an 'unexpected language feature'?
 For example:

 a = [1,2,3,4]
 a[]   = returns 1


 Thanks.





Re: [julia-users] A[]: Accessing array with empty index

2014-05-30 Thread Steven G. Johnson


On Friday, May 30, 2014 5:19:35 PM UTC-4, Carlos Becker wrote:

 HI Jacob,

 I get that, but which is the reasoning behind myArray[] ? 
 why should it return a ref to the 1st element?


Because you can have a 0-dimensional array, and a 0-dimensional array 
contains exactly 1 element (the empty product of the dimensions).