-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Labels
designDesign of APIs or of the language itselfDesign of APIs or of the language itself
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
lengthis 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
stepalready has its own nice syntax (a:b:c),lengthis 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:cdo the same thing. I don't think this is a serious problem since thea:b:csyntax 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, thelengthkeyword was calledNor something explicit like that. - It's not very nice to have the same argument as both positional and keyword.
jg110, matthieugomez, jebej, DNF2, briochemc and 2 morefredrikekre, MasonProtter, pwstokes225 and nalimilanmkitti, pdeffebach and pwstokes225
Metadata
Metadata
Assignees
Labels
designDesign of APIs or of the language itselfDesign of APIs or of the language itself