-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
up_to doesnt work correctly when range start is 0 #1439
Comments
Thank you for the report! Looks like a silly mistake in the definition of
|
❤️ |
Related #1361 |
As per discussions on discord, |
Does it? Because I see nothing wrong with just defining
|
That also works! |
I don't like the inconsistency here. We are using the word "up" in the first function but not in the second one. IMO more consistent versions are |
W8 so the perceived inconsistency is "not all english expressions start with the same word"? |
No, but I feel that it is strange that the functions doing almost the same thing use different English constructs. If I know the function |
Ok, as we discussed on Discord, lets use the following API:
Please note that |
I was thinking more about this issue and I think the proposed design (described by me in the previous comment is still wrong). The problem with inconsistency in the API is very serious and we need to start designing APIs with much bigger caution. It may seem unharmful at the first sight, but it has serious consequences that we would not be able to resolve long-term if we do not put enough care right now. There are few fundamentals for this:
Regarding the problem with
Using such naming convention:
Of course, each function above should have optional arguments:
|
@wdanilo Please make a decision. |
@iamrecursion Can we just use what I described above? |
can we stick to simply 'range', or 'until' and allow no special syntax so that range 0..5 represent 0,1,2,3,4,5 and range 1..6 will represent 1,2,3,4,5,6 and both will have the same number of elements (6) and both always start- and end- inclusive. give a choice to allow or disallow reverse direction. also allow a stepby option but validate its value at runtime so it agrees with range direction.
just my 2 cents.
thanks,manny
On Thursday, March 25, 2021, 5:13:28 AM PDT, Wojciech Daniło ***@***.***> wrote:
@iamrecursion Can we just use what I described above?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
@manyone Could you elaborate more? Especially, what do you mean by "no special syntax"? We have a syntax of |
by special syntax i was referring to the confusing way of coding 0.up_to 7 in order to get a vector of 0..6
what i meant was - why come up with multiple aliases when you can use only one form and tell our users of its behavior, namely - if you use say, 'from_to' START..END, it will iterate from START to END, inclusive - always ...
UNLESS an optional parameter, DIRECTION, is present which indicates
+1 means enforce increasing only
-1 means enforce decreasing only
0 - any direction allowed.
![image](https://user-images.githubusercontent.com/7508243/112592369-18413d80-8dc3-11eb-8713-3db735ef7185.png)
| from | to | length | direction | result |
| 0 | 5 | 6 | 1 | [0,1,2,3,4,5] |
| 0 | 5 | 6 | -1 | error |
| 0 | 5 | 6 | 0 | [0,1,2,3,4,5] |
| 5 | 0 | 6 | 1 | error |
| 5 | 0 | 6 | -1 | [5,4,3,2,1,0] |
| 5 | 0 | 6 | 0 | [5,4,3,2,1,0] |
| 1 | 6 | 6 | 1 | [1,2,3,4,5,6] |
| 1 | 6 | 6 | -1 | error |
| 1 | 6 | 6 | 0 | [1,2,3,4,5,6] |
| 6 | 0 | 6 | 1 | error |
| 6 | 0 | 6 | -1 | [6,5,4,3,2,1] |
| 6 | 0 | 6 | 0 | [6,5,4,3,2,1] |
On Thursday, March 25, 2021, 12:29:14 PM PDT, Wojciech Daniło ***@***.***> wrote:
@manyone Could you elaborate more? Especially, what do you mean by "no special syntax"? We have a syntax of 1 .. 6 - is this the special syntax you are talking about? Also, in my proposal above, there is a function range which is alias for this special sytnax which does exactly what you have written - it is inclusive by default, and works in both ascending and descending orders. There are also aliases like up_to or down_to which can be used if you want to be sure that the input provided for example by the user of your function should iterate in ascending or descending order only. Would you be so nice and provide a table of function that you would implement instead of the table I provided above with a justification why the things I provided are misdesigned for you, please? :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
@manyone, regarding In my opinion, there are many cases why we would need to provide several aliases. Sometimes, you want to design a function that will take 2 numbers and will convert that to an ascending range (and only ascending!). So then, you can use |
sorry, i didn't mean to throw a monkey wrench into the process ..
as a matter of fact,the range function would be perfect for my needs. even the up_to may work. my only hesitation about using an alias is that the start & end might be different than expected at run time.but otherwise range and up_to will work for me 99.9% of the time.
i love enso - i've never had so much fun coding!keep up the good work.
thanks,manny
On Friday, March 26, 2021, 10:47:33 AM PDT, Wojciech Daniło ***@***.***> wrote:
@manyone, regarding confusing way of coding 0.up_to 7 in order to get a vector of 0..6 - this is a bug in the current stdlib and it is not present anymore in my proposal above. In my proposal, there is up_to function which is marked as inclusive by default on both ends.
In my opinion, there are many cases why we would need to provide several aliases. Sometimes, you want to design a function that will take 2 numbers and will convert that to an ascending range (and only ascending!). So then, you can use up_to. If you want a generic functionality that you have described, in my proposal above there is a range function that behaves exactly as in your table. Would you be so nice and take a look at my table again and check if the proposed functions, especially range suit your needs then?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Fixed in #1702 |
General Summary
the up_to operator doesnt work correctly when range starts at 0.
Steps to Reproduce
The text was updated successfully, but these errors were encountered: