Seems like this has the makings of a nice package for debugging.

Best,
--Tim

On Wednesday, December 02, 2015 01:49:22 AM Eric Forgy wrote:
> Some more improvements...
> 
> julia> n = 5
> 5
> 
> julia> for i = n
>        println(i)
>        end
> 5
> 
> julia> using strict
> 
> julia> for i = n
>        println(i)
>        end
> ERROR: MethodError: `start` has no method matching start(::Type{Number})
>  in start at C:\Users\Eric Forgy\.julia\v0.4\strict\src\strict.jl:24
> 
> On Wednesday, December 2, 2015 at 12:05:07 PM UTC+8, Eric Forgy wrote:
> > It's a start :)
> > 
> > https://github.com/EricForgy/strict.jl
> > 
> > 
> > julia> using strict
> > 
> > julia> a = 5
> > 5
> > 
> > julia> a[1]
> > ERROR: MethodError: `getindex` has no method matching getindex(::Type{
> > Number}, ::Type{Integer})
> > 
> > Closest candidates are:
> >   getindex(::Type{T}, ::Any...)
> >   getindex{T<:Union{Char,Number}}(::Type{T<:Union{Char,Number}}, ::Range{T
> > 
> > })
> > 
> >   getindex{T<:Union{Char,Number}}(::Type{T<:Union{Char,Number}}, ::Range{T
> > 
> > }, ::Range{T}...)
> > 
> >  in getindex at C:\Users\Eric Forgy\.julia\v0.4\strict\src\strict.jl:4
> > 
> > On Wednesday, December 2, 2015 at 11:02:45 AM UTC+8, Tim Holy wrote:
> >> Likewise, I do see why this is a little troublesome. It's annoying when
> >> you
> >> mean to write `for i = 1:n` but accidentally write `for i = n`; it's not
> >> always an easy bug to find.
> >> 
> >> --Tim
> >> 
> >> On Tuesday, December 01, 2015 06:38:46 PM Eric Forgy wrote:
> >> > 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