It bugs me, but only a little, so I won't lose sleep over it :)

Then again, I wish Julia had a "strict" mode. In strict mode, the language 
would be more pure mathematically, e.g. scalars have no indices, the 
transpose of a vector is a covector, etc. This bit me recently because if T 
<: U, then Array{T} is NOT <: Array{U} although as, sub-modules 
<https://en.wikipedia.org/wiki/Module_(mathematics)>, Tmodule <: Umodule.

Then again, as I'm learning, if we want Julia to do something bad enough, 
e.g. have a "strict" mode,  we can have it. For example, I could write a 
package "strict.jl" where 

using strict

would kill Base.getindex(::Number) and things like that. That could be cool 
:)

On Wednesday, December 2, 2015 at 9:38:50 AM UTC+8, Tim Holy wrote:
>
> On Tuesday, December 01, 2015 03:19:33 PM Eric Forgy wrote: 
> > A scalar is distinct from a vector so size(a) = () makes sense. getindex 
> for 
> > a scalar does not make sense and should probably be removed on the 
> grounds 
> > of mathematical elegance :) Any code that depends on referencing a 
> scalar 
> > via an index is probably flawed in the first place. 
>
> Conversely, there are many people who seem to want Julia to treat scalars 
> and 
> 1-vectors indistinguishably (ala Matlab). 
>
> For what it's worth, here's a (contrived) example to justify the current 
> behavior: 
>
> function sum_over_dims(A, dims) 
>     for d in dims 
>         A = sum(A, d) 
>     end 
>     A 
> end 
>
> sum_over_dims(A, [2,3]) 
> sum_over_dims(A, 2) 
>
> Why should I write sum_over_dims(A, [2]) in the latter case? 
>
> Best, 
> --Tim 
>
>

Reply via email to