-
Notifications
You must be signed in to change notification settings - Fork 16
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
Review zero and null values for Ranges #410
Comments
Seems that use of Nil as an endpoint for Range is already problematic: Welcome to Rakudo™ v2023.10.
but
So somewhere in the code there's an "implicit assumption" that Nil < 0 |
So, a cleaner approach would be to define a (new) symbol for the null Range such as:
𝟘 with texas variant like
Then "all" that needs to be done in core is:
|
https://docs.raku.org/language/operators#Identity would also need to be updated |
I'm not following your reasoning. To me |
We can express an undefined Range already. It is I do agree that ranges with undefined values (Nil, Type-Objects) should result in an undefined Range, so that any Ranges with type objects like I can't thinks of a case where the construction of an impossible Range would not be a bug. So The whole thing is tricky to decide because Raku is ment to soldier on, even if odd values pop up in any container that is not guarded by |
What about:
|
I find that the best way to characterize an interval (a Range) is that it is a set of values such that the set is possibly of infinite cardinality, eg when you have 2 real numbers or 2 character strings as endpoints, in contrast with a typical set defined in terms of an enumeration of individual values and therefore is of finite cardinality. This is particularly true in the case of a set of intervals which can be non-continuous. And so, when considering what is reasonable behavior, we should try and define semantics for a Range which are logically consistent with semantics for a set. |
Continuing on, for the generic case of a Range of Any...
|
I feel that while it may not make sense conceptually to sort different types, eg it doesn't make sense to sort numbers and strings, if Raku at least provides a deterministic default generic sort that can compare two Any and give a defined result, then a Range can always function with any 2 end points no matter what they are. Same as generic equality should always be defined between any 2 things, returning a defined result, although arguably that is easier to argue for and implement than generic sorting. And if it doesn't make conceptual sense, the solution is to just not combine both types in the same Range, but if someone does it, it should "work". |
Some very good & thoughful comments - let me try and summarize my reaction (corrections to the are welcome if anything is misconstrued): As a consumer of raku, I think the following makes most sense:
this is what we have today in 6.e.PREVIEW - phew! rationale
Implementors (see below) can use I am not sure about warn. Specifically on my Math::Interval module, this has the following effect:
|
To reassure this: |
As I see it, Whatever is decided for Ranges, please table it until Thank you. |
@jubilatious1 ... I am relaxed about what the core dev team decides has priority, but I am surprised that comma separated triple-dot Sequences are the go to option for array indices - anyway that issue is the place to discuss more fully, I guess... |
Currently, v.6.e.PREVIEW, we have the following:
My (naive) assertions are that:
0..0
should be reserved as the (only) 'zero Range'so that
and that (if ever defined) a Range div Range operation could then fail with 0..0 as the denominator
and
Nil..Nil
should be reserved as the (only) 'null Range'so that
Since 6.e.PREVIEW is making a breaking change to the behaviour of Nil..Nil, I would suggest we try to squeeze in the latter as a fix prior to closing 6.e production...?
See this SO question for some context:
https://stackoverflow.com/questions/77608044/is-there-an-elegant-way-in-raku-to-see-if-two-ranges-overlap
The text was updated successfully, but these errors were encountered: