Closed
Description
I discovered from a typo today that the length
method is defined on numbers:
julia> length(5)
1
julia> length(pi)
1
It's defined here: https://github.com/JuliaLang/julia/blob/master/base/number.jl#L12. Why is length
defined on numbers? This seems counterintuitive. Numbers aren't iterable in any way after all.
Metadata
Metadata
Assignees
Labels
No labels
Activity
joehuchette commentedon Jun 19, 2015
They are in Julia:
samuela commentedon Jun 19, 2015
AHH, BUT WHYYY?
nalimilan commentedon Jun 19, 2015
It's considered practical by some people. The question is rather whether this has drawbacks or not. Else there's no reason to remove that.
FWIW, please use the mailing list for questions in the future, and keep GitHub for bug reports.
Keno commentedon Jun 19, 2015
FWIW, I consider this a mistake, it has bitten me way too many times.
carnaval commentedon Jun 19, 2015
I also find it a bad idea, but github may not be the place to revive the debate
samuela commentedon Jun 19, 2015
This just reeks of MATLAB to me.
jakebolewski commentedon Jun 19, 2015
@samuela the supported iteration / indexing interface is to basically treat scalars as zero dimensional arrays.
Keno commentedon Jun 19, 2015
It is way too easy to miss a colon in a for loop and only do one iteration - I remember vividly how I spent a week debugging why my locality sensitive hash wasn't local - I had
for i = x
instead offor i = 1:x
for the number of rounds boom.nalimilan commentedon Jun 19, 2015
Yeah, I'm not a great fan of this either. :-/
JeffBezanson commentedon Jun 19, 2015
Yes I really think we should experiment with removing iteration of numbers. I think the array indexing redesign might make this possible.
johnmyleswhite commentedon Jun 19, 2015
This is the bug I most often hit these days.
mbauman commentedon Jun 19, 2015
Here was my last 15-minute attempt at making numbers non-iterable: #10331 (comment)
carlobaldassi commentedon Jun 19, 2015
Just to balance the opinions here, I'll mention I use this feature a lot and find it quite handy.
joehuchette commentedon Jun 19, 2015
@carlobaldassi what does a typical use look like?
27 remaining items