Closed
Description
This issue is to propose defining range(start, stop, length) = range(start, stop; length=length)
. I searched the issues and PR, expecting pages of heated debate, but I couldn't find any, so here goes.
Pros:
- It's really really useful syntax. Doing
grep -r ' range('
in my .julia/packages returns lots of hits, almost all of which arerange(start, stop; length=length)
. Doing the same in my research codes has a lot more, all of them of this form. Most of my usage is either discretization of a differential equation or plotting of a function. - Having to type
length
is very annoying. I think this is the reason why some people useLinRange
, which increases fragmentation and makes people use LinRange when they probably shouldn't (it's low-level compared torange
) - This definition doesn't break anything
step
already has its own nice syntax (a:b:c
),length
is missing one
Cons:
- Range has a large ambiguity between the different ways of specifying it, and this would force a default choice.
- It could plausibly be thought that
range(a, b, c)
anda:b:c
do the same thing. I don't think this is a serious problem since thea:b:c
syntax is clearly special, and not analogous to function calls (since the additional argument comes in the middle) range(a, b, c)
andLinRange(a, b, c)
would not be similar syntax for different things- It's clear at first sight what
range(0, 1, length=100)
does;range(0, 1, 100)
is more implicit and can plausibly cause confusion. I think it's usually clear from the context. In most of examples taken from my usage, thelength
keyword was calledN
or something explicit like that. - It's not very nice to have the same argument as both positional and keyword.