Pontus, if your function call is sometimes returning a range and sometimes 
returning an integer, then you may have a type-stability issue anyway. To make 
it type-stable, you may want to have it return 17:17.


Regarding integers-as-iterables, I think the issue is that it makes it much 
easier to write generic code. For example:

function twoloops(index1, index2)
    for i2 in index2
        for i1 in index1
            println(i1, " ", i2)
        end
    end
end

This code works for all of these:
twoloops(1:2, 1:3)
twoloops(5, 1:3)
twoloops(6:8, 4)

If integers weren't iterables, either one would force the user to call this as
twoloops(1:2, 1:3)
twoloops(5:5, 1:3)
twoloops(6:8, 4:4)

or define functions of different signatures
twoloops(index1::AbstractVector, index2::AbstractVector)
twoloops(index1::Real, index2::AbstractVector)
twoloops(index1::AbstractVector, index2::Real)

--Tim

On Wednesday, June 18, 2014 01:24:43 AM Ivar Nesje wrote:
> I don't think this is a parser issue. It would be strange to not allow
> integers specifically in a context where we accept anything else.
> 
> The problem is how integers are defined as iterable in
> base/number.jl#L36-l39
> <https://github.com/JuliaLang/julia/blob/master/base/number.jl#L36-l39>,
> I'm sure I read some discussion about this behaviour somewhere, but I can't
> find it. I think the argument for them was that it would be somewhat
> friendly to Matlab users.
> 
> Ivar
> 
> kl. 09:28:01 UTC+2 onsdag 18. juni 2014 skrev Pontus Stenetorp følgende:
> > Everyone,
> > 
> > I am sure that there is a perfectly good reason for the parser to
> > 
> > allow a construct like:
> >     for i in 17; println(i); end
> > 
> > But, I am unable to see how this can be useful/helpful since a loop
> > like this will only ever execute once.  I have now had two bugs
> > stemming from this behaviour, for both cases `17` was replaced with a
> > function call.  What I intended to write was something like the
> > 
> > following:
> >     for i in 1:17; println(i); end
> > 
> > Thus, I thought it was a good idea to ask about this, according to me,
> > little peculiarity, so that I can determine whether I am introducing
> > bugs/rambling on due to my own ignorance, or if this is indeed
> > something that should be fixed.  For those interested and familiar
> > 
> > with the Julia introspection, here is the dump of the expression:
> >     julia> dump(:(for i in 17; println(i); end))
> >     Expr
> >     
> >       head: Symbol for
> >       args: Array(Any,(2,))
> >       
> >         1: Expr
> >         
> >           head: Symbol =
> >           args: Array(Any,(2,))
> >           
> >             1: Symbol i
> >             2: Int64 17
> >           
> >           typ: Any
> >         
> >         2: Expr
> >         
> >           head: Symbol block
> >           args: Array(Any,(2,))
> >           
> >             1: LineNumberNode
> >             
> >               line: Int64 1
> >             
> >             2: Expr
> >             
> >               head: Symbol call
> >               args: Array(Any,(2,))
> >               typ: Any
> >           
> >           typ: Any
> >       
> >       typ: Any
> > 
> > For reference, I am running a fairly recent master version of Julia
> > (master/8f1fbec*).
> > 
> >     Pontus

Reply via email to