Skip to content
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

Closed interval maybe a mistake? #314

Open
skiars opened this issue Feb 10, 2023 · 8 comments
Open

Closed interval maybe a mistake? #314

skiars opened this issue Feb 10, 2023 · 8 comments

Comments

@skiars
Copy link
Member

skiars commented Feb 10, 2023

In my current experience, the expression 0..5 means that [0,1,2,3,4,5] doesn't seem to work as well as [0,1,2,3,4], so the half-closed interval $[a, b)$ might be better?

@s-hadinger
Copy link
Contributor

I'm afraid it would be a huge breaking change.

What about the math version: [0..5] for [0,1,2,3,4,5] and [0..5[ for [0,1,2,3,4] (if the syntax is possible)

The other option would be to use the Python equivalent [0:5]

@skiars
Copy link
Member Author

skiars commented Feb 10, 2023

Indeed, and I find some interesting uses of range:

> [1, 2, 3, 4][0 .. -1]
[1, 2, 3, 4]
> [1, 2, 3, 4][0 .. 0] # not an empty range
[1]
> [1, 2, 3, 4][0 .. -4]
[1]
> [1, 2, 3, 4][0 .. -5]
[]

@nobodywasishere
Copy link

You could also use Ruby syntax by adding another dot, but i can see how that would be confusing.

> [0..5]
[0,1,2,3,4,5]
> [0...5]
[0,1,2,3,4]

Another idea is having ..= and ..< to be more explicit, but it may look too ugly/verbose

> [0..=5]
[0,1,2,3,4,5]
> [0..<5]
[0,1,2,3,4]

@skiars
Copy link
Member Author

skiars commented Oct 9, 2023

The other option would be to use the Python equivalent [0:5]

I agree with this.

@s-hadinger
Copy link
Contributor

Revisiting some old issues. Are you still in favor of this syntax for excluded last value?

@bartgrantham
Copy link

I'm just a casual observer who thinks Berry is really neat, but IMHO Python's a[start:stop:step] slice syntax strikes a nice balance between expressiveness and complexity. Especially with support for negative numbers.

@skiars
Copy link
Member Author

skiars commented Dec 11, 2024

This may be possible. Considering:

# if operator : has the following rules:
a : b # => range(a, b) if `a`, `b` is integer
a : b # => range(a.lower(), a.upper(), b) if `a` is a range, then update its step!

# examples:
1 : 10 : 2 # => range(1, 10, 2)

@skiars
Copy link
Member Author

skiars commented Dec 11, 2024

Revisiting some old issues. Are you still in favor of this syntax for excluded last value?

It doesn't seem like a big deal?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants