* [ruby-core:87313] [Ruby trunk Feature#14799] Startless range
[not found] <redmine.issue-14799.20180531075634@ruby-lang.org>
@ 2018-05-31 7:56 ` zverok.offline
2018-05-31 8:10 ` [ruby-core:87314] " shyouhei
` (14 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: zverok.offline @ 2018-05-31 7:56 UTC (permalink / raw)
To: ruby-core
Issue #14799 has been reported by zverok (Victor Shepelev).
----------------------------------------
Feature #14799: Startless range
https://bugs.ruby-lang.org/issues/14799
* Author: zverok (Victor Shepelev)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
On introduction of endless range at #12912, "startless range" was discussed this way:
> @sowieso: Not having the opposite (`..5` and `..-2`) feels like this is rather a hack than a thoroughly planned feature.
> @duerst: I don't understand the need for a `..5` Range. The feature is called "endless range". Although mathematically, it's possible to think about startless ranges, they don't work in a program. Maybe some programming languages have `..5` as a shortcut for `0..5`, but that's in any way a usual, bounded, range with a start and an end. It's conceptually totally different from `5..`, which is a range with a start but no end, an unbound range.
In the context of that ticket (ranges used mostly for slicing arrays) having `..5` was indeed hard to justify, but there are other cases when `..5` being `-Infinity..5` is absolutely reasonable:
```ruby
case release_date
when ..1.year.ago
puts "ancient"
when 1.year.ago..3.months.ago
puts "old"
when 3.months.ago..Date.today
puts "recent"
when Date.today..
puts "upcoming"
end
log.map(&:logged_at).grep(..Date.new(1980)) # => outliers due to bad log parsing...
```
E.g., whenever case equality operator is acting, having startless range to express "below this value" is the most concise and readable way. Also, for expressing constants (mostly decorative, but very readable):
```ruby
# Celsius degrees
WORK_RANGES = {
..-10 => :turn_off,
-10..0 => :energy_saving,
0..20 => :main,
20..35 => :cooling,
35.. => :turn_off
}
```
In addition, my related proposal #14784 suggests that this kind of ranges could be utilized by more powerful clamp too:
```ruby
updated_at.clamp(..Date.today)
```
**Uncertainty points:**
* Would it be hard to add to parser? I am not sure, I am not very good at it :(
* Should `..` be a thing? I guess not, unless there would be convincing real-life examples, which for me it is hard to think of.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 16+ messages in thread
* [ruby-core:87314] [Ruby trunk Feature#14799] Startless range
[not found] <redmine.issue-14799.20180531075634@ruby-lang.org>
2018-05-31 7:56 ` [ruby-core:87313] [Ruby trunk Feature#14799] Startless range zverok.offline
@ 2018-05-31 8:10 ` shyouhei
2018-05-31 9:14 ` [ruby-core:87315] " zverok.offline
` (13 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: shyouhei @ 2018-05-31 8:10 UTC (permalink / raw)
To: ruby-core
Issue #14799 has been updated by shyouhei (Shyouhei Urabe).
No strong opinion on this. However let me leave one question: how should Range#each work for this kind of ranges?
----------------------------------------
Feature #14799: Startless range
https://bugs.ruby-lang.org/issues/14799#change-72307
* Author: zverok (Victor Shepelev)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
On introduction of endless range at #12912, "startless range" was discussed this way:
> @sowieso: Not having the opposite (`..5` and `..-2`) feels like this is rather a hack than a thoroughly planned feature.
> @duerst: I don't understand the need for a `..5` Range. The feature is called "endless range". Although mathematically, it's possible to think about startless ranges, they don't work in a program. Maybe some programming languages have `..5` as a shortcut for `0..5`, but that's in any way a usual, bounded, range with a start and an end. It's conceptually totally different from `5..`, which is a range with a start but no end, an unbound range.
In the context of that ticket (ranges used mostly for slicing arrays) having `..5` was indeed hard to justify, but there are other cases when `..5` being `-Infinity..5` is absolutely reasonable:
```ruby
case release_date
when ..1.year.ago
puts "ancient"
when 1.year.ago..3.months.ago
puts "old"
when 3.months.ago..Date.today
puts "recent"
when Date.today..
puts "upcoming"
end
log.map(&:logged_at).grep(..Date.new(1980)) # => outliers due to bad log parsing...
```
E.g., whenever case equality operator is acting, having startless range to express "below this value" is the most concise and readable way. Also, for expressing constants (mostly decorative, but very readable):
```ruby
# Celsius degrees
WORK_RANGES = {
..-10 => :turn_off,
-10..0 => :energy_saving,
0..20 => :main,
20..35 => :cooling,
35.. => :turn_off
}
```
In addition, my related proposal #14784 suggests that this kind of ranges could be utilized by more powerful clamp too:
```ruby
updated_at.clamp(..Date.today)
```
**Uncertainty points:**
* Would it be hard to add to parser? I am not sure, I am not very good at it :(
* Should `..` be a thing? I guess not, unless there would be convincing real-life examples, which for me it is hard to think of.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 16+ messages in thread
* [ruby-core:87315] [Ruby trunk Feature#14799] Startless range
[not found] <redmine.issue-14799.20180531075634@ruby-lang.org>
2018-05-31 7:56 ` [ruby-core:87313] [Ruby trunk Feature#14799] Startless range zverok.offline
2018-05-31 8:10 ` [ruby-core:87314] " shyouhei
@ 2018-05-31 9:14 ` zverok.offline
2018-05-31 9:31 ` [ruby-core:87316] " shyouhei
` (12 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: zverok.offline @ 2018-05-31 9:14 UTC (permalink / raw)
To: ruby-core
Issue #14799 has been updated by zverok (Victor Shepelev).
> how should Range#each work for this kind of ranges?
Most probably it should not (the same as `Enumerable#reverse_each` or `last(5)` doesn't have a sense for already implemented endless ranges), just raise.
----------------------------------------
Feature #14799: Startless range
https://bugs.ruby-lang.org/issues/14799#change-72308
* Author: zverok (Victor Shepelev)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
On introduction of endless range at #12912, "startless range" was discussed this way:
> @sowieso: Not having the opposite (`..5` and `..-2`) feels like this is rather a hack than a thoroughly planned feature.
> @duerst: I don't understand the need for a `..5` Range. The feature is called "endless range". Although mathematically, it's possible to think about startless ranges, they don't work in a program. Maybe some programming languages have `..5` as a shortcut for `0..5`, but that's in any way a usual, bounded, range with a start and an end. It's conceptually totally different from `5..`, which is a range with a start but no end, an unbound range.
In the context of that ticket (ranges used mostly for slicing arrays) having `..5` was indeed hard to justify, but there are other cases when `..5` being `-Infinity..5` is absolutely reasonable:
```ruby
case release_date
when ..1.year.ago
puts "ancient"
when 1.year.ago..3.months.ago
puts "old"
when 3.months.ago..Date.today
puts "recent"
when Date.today..
puts "upcoming"
end
log.map(&:logged_at).grep(..Date.new(1980)) # => outliers due to bad log parsing...
```
E.g., whenever case equality operator is acting, having startless range to express "below this value" is the most concise and readable way. Also, for expressing constants (mostly decorative, but very readable):
```ruby
# Celsius degrees
WORK_RANGES = {
..-10 => :turn_off,
-10..0 => :energy_saving,
0..20 => :main,
20..35 => :cooling,
35.. => :turn_off
}
```
In addition, my related proposal #14784 suggests that this kind of ranges could be utilized by more powerful clamp too:
```ruby
updated_at.clamp(..Date.today)
```
**Uncertainty points:**
* Would it be hard to add to parser? I am not sure, I am not very good at it :(
* Should `..` be a thing? I guess not, unless there would be convincing real-life examples, which for me it is hard to think of.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 16+ messages in thread
* [ruby-core:87316] [Ruby trunk Feature#14799] Startless range
[not found] <redmine.issue-14799.20180531075634@ruby-lang.org>
` (2 preceding siblings ...)
2018-05-31 9:14 ` [ruby-core:87315] " zverok.offline
@ 2018-05-31 9:31 ` shyouhei
2018-05-31 9:51 ` [ruby-core:87317] " zverok.offline
` (11 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: shyouhei @ 2018-05-31 9:31 UTC (permalink / raw)
To: ruby-core
Issue #14799 has been updated by shyouhei (Shyouhei Urabe).
zverok (Victor Shepelev) wrote:
> > how should Range#each work for this kind of ranges?
>
> Most probably it should not (the same as `Enumerable#reverse_each` or `last(5)` doesn't have a sense for already implemented endless ranges), just raise.
Sounds reasonable, except it seems endless range does not raise for #reverse_each :)
```
zsh % ruby -ve '(1..).reverse_each {|i| p i }'
ruby 2.6.0dev (2018-05-29 trunk 63514) [x86_64-darwin15]
^CTraceback (most recent call last):
2: from -e:1:in `<main>'
1: from -e:1:in `reverse_each'
-e:1:in `each': Interrupt
```
----------------------------------------
Feature #14799: Startless range
https://bugs.ruby-lang.org/issues/14799#change-72309
* Author: zverok (Victor Shepelev)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
On introduction of endless range at #12912, "startless range" was discussed this way:
> @sowieso: Not having the opposite (`..5` and `..-2`) feels like this is rather a hack than a thoroughly planned feature.
> @duerst: I don't understand the need for a `..5` Range. The feature is called "endless range". Although mathematically, it's possible to think about startless ranges, they don't work in a program. Maybe some programming languages have `..5` as a shortcut for `0..5`, but that's in any way a usual, bounded, range with a start and an end. It's conceptually totally different from `5..`, which is a range with a start but no end, an unbound range.
In the context of that ticket (ranges used mostly for slicing arrays) having `..5` was indeed hard to justify, but there are other cases when `..5` being `-Infinity..5` is absolutely reasonable:
```ruby
case release_date
when ..1.year.ago
puts "ancient"
when 1.year.ago..3.months.ago
puts "old"
when 3.months.ago..Date.today
puts "recent"
when Date.today..
puts "upcoming"
end
log.map(&:logged_at).grep(..Date.new(1980)) # => outliers due to bad log parsing...
```
E.g., whenever case equality operator is acting, having startless range to express "below this value" is the most concise and readable way. Also, for expressing constants (mostly decorative, but very readable):
```ruby
# Celsius degrees
WORK_RANGES = {
..-10 => :turn_off,
-10..0 => :energy_saving,
0..20 => :main,
20..35 => :cooling,
35.. => :turn_off
}
```
In addition, my related proposal #14784 suggests that this kind of ranges could be utilized by more powerful clamp too:
```ruby
updated_at.clamp(..Date.today)
```
**Uncertainty points:**
* Would it be hard to add to parser? I am not sure, I am not very good at it :(
* Should `..` be a thing? I guess not, unless there would be convincing real-life examples, which for me it is hard to think of.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 16+ messages in thread
* [ruby-core:87317] [Ruby trunk Feature#14799] Startless range
[not found] <redmine.issue-14799.20180531075634@ruby-lang.org>
` (3 preceding siblings ...)
2018-05-31 9:31 ` [ruby-core:87316] " shyouhei
@ 2018-05-31 9:51 ` zverok.offline
2018-05-31 11:39 ` [ruby-core:87318] [Ruby trunk Feature#14799][Assigned] " mame
` (10 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: zverok.offline @ 2018-05-31 9:51 UTC (permalink / raw)
To: ruby-core
Issue #14799 has been updated by zverok (Victor Shepelev).
> except it seems endless range does not raise for #reverse_each :)
Funny!
Though, in fact, raises some big questions about `Enumerable` implementations. As far as I can understand, most of `Enumerable`'s methods aren't redefined in `Range`, which leaves a room for optimization (and sometimes a huge room): `last(N)` and `reverse_each` are just work by converting enumerable to an Array, and then taking the last elements. Probably, providing custom `#reverse_each` for where it is acceptable, and making `#last` rely on this could be both more effective, and produce more reasonable result in edge cases (like open -- semi-infinite -- sequences).
----------------------------------------
Feature #14799: Startless range
https://bugs.ruby-lang.org/issues/14799#change-72310
* Author: zverok (Victor Shepelev)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
On introduction of endless range at #12912, "startless range" was discussed this way:
> @sowieso: Not having the opposite (`..5` and `..-2`) feels like this is rather a hack than a thoroughly planned feature.
> @duerst: I don't understand the need for a `..5` Range. The feature is called "endless range". Although mathematically, it's possible to think about startless ranges, they don't work in a program. Maybe some programming languages have `..5` as a shortcut for `0..5`, but that's in any way a usual, bounded, range with a start and an end. It's conceptually totally different from `5..`, which is a range with a start but no end, an unbound range.
In the context of that ticket (ranges used mostly for slicing arrays) having `..5` was indeed hard to justify, but there are other cases when `..5` being `-Infinity..5` is absolutely reasonable:
```ruby
case release_date
when ..1.year.ago
puts "ancient"
when 1.year.ago..3.months.ago
puts "old"
when 3.months.ago..Date.today
puts "recent"
when Date.today..
puts "upcoming"
end
log.map(&:logged_at).grep(..Date.new(1980)) # => outliers due to bad log parsing...
```
E.g., whenever case equality operator is acting, having startless range to express "below this value" is the most concise and readable way. Also, for expressing constants (mostly decorative, but very readable):
```ruby
# Celsius degrees
WORK_RANGES = {
..-10 => :turn_off,
-10..0 => :energy_saving,
0..20 => :main,
20..35 => :cooling,
35.. => :turn_off
}
```
In addition, my related proposal #14784 suggests that this kind of ranges could be utilized by more powerful clamp too:
```ruby
updated_at.clamp(..Date.today)
```
**Uncertainty points:**
* Would it be hard to add to parser? I am not sure, I am not very good at it :(
* Should `..` be a thing? I guess not, unless there would be convincing real-life examples, which for me it is hard to think of.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 16+ messages in thread
* [ruby-core:87318] [Ruby trunk Feature#14799][Assigned] Startless range
[not found] <redmine.issue-14799.20180531075634@ruby-lang.org>
` (4 preceding siblings ...)
2018-05-31 9:51 ` [ruby-core:87317] " zverok.offline
@ 2018-05-31 11:39 ` mame
2018-05-31 13:01 ` [ruby-core:87320] [Ruby trunk Feature#14799] " janosch84
` (9 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: mame @ 2018-05-31 11:39 UTC (permalink / raw)
To: ruby-core
Issue #14799 has been updated by mame (Yusuke Endoh).
File beginless-range.patch added
Status changed from Open to Assigned
Assignee set to matz (Yukihiro Matsumoto)
I tried begin-less range once, and it caused many parser conflicts, so I gave up.
However, I've tried it again and created a patch with no conflicts.
A proof-of-concept patch is attached. It uses the damn lexer state, so I'd like nobu and yui-knk to review it.
Note that the main focus of this patch is parse.y, so we need more work to let many builtin methods to support begin-less range.
Matz, what do you think?
----------------------------------------
Feature #14799: Startless range
https://bugs.ruby-lang.org/issues/14799#change-72311
* Author: zverok (Victor Shepelev)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
----------------------------------------
On introduction of endless range at #12912, "startless range" was discussed this way:
> @sowieso: Not having the opposite (`..5` and `..-2`) feels like this is rather a hack than a thoroughly planned feature.
> @duerst: I don't understand the need for a `..5` Range. The feature is called "endless range". Although mathematically, it's possible to think about startless ranges, they don't work in a program. Maybe some programming languages have `..5` as a shortcut for `0..5`, but that's in any way a usual, bounded, range with a start and an end. It's conceptually totally different from `5..`, which is a range with a start but no end, an unbound range.
In the context of that ticket (ranges used mostly for slicing arrays) having `..5` was indeed hard to justify, but there are other cases when `..5` being `-Infinity..5` is absolutely reasonable:
```ruby
case release_date
when ..1.year.ago
puts "ancient"
when 1.year.ago..3.months.ago
puts "old"
when 3.months.ago..Date.today
puts "recent"
when Date.today..
puts "upcoming"
end
log.map(&:logged_at).grep(..Date.new(1980)) # => outliers due to bad log parsing...
```
E.g., whenever case equality operator is acting, having startless range to express "below this value" is the most concise and readable way. Also, for expressing constants (mostly decorative, but very readable):
```ruby
# Celsius degrees
WORK_RANGES = {
..-10 => :turn_off,
-10..0 => :energy_saving,
0..20 => :main,
20..35 => :cooling,
35.. => :turn_off
}
```
In addition, my related proposal #14784 suggests that this kind of ranges could be utilized by more powerful clamp too:
```ruby
updated_at.clamp(..Date.today)
```
**Uncertainty points:**
* Would it be hard to add to parser? I am not sure, I am not very good at it :(
* Should `..` be a thing? I guess not, unless there would be convincing real-life examples, which for me it is hard to think of.
---Files--------------------------------
beginless-range.patch (3.55 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 16+ messages in thread
* [ruby-core:87320] [Ruby trunk Feature#14799] Startless range
[not found] <redmine.issue-14799.20180531075634@ruby-lang.org>
` (5 preceding siblings ...)
2018-05-31 11:39 ` [ruby-core:87318] [Ruby trunk Feature#14799][Assigned] " mame
@ 2018-05-31 13:01 ` janosch84
2018-06-04 11:10 ` [ruby-core:87388] " darkwiiplayer
` (8 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: janosch84 @ 2018-05-31 13:01 UTC (permalink / raw)
To: ruby-core
Issue #14799 has been updated by janosch-x (Janosch Müller).
Rails devs could also make use of this, e.g. in [queries](http://guides.rubyonrails.org/active_record_querying.html#range-conditions).
----------------------------------------
Feature #14799: Startless range
https://bugs.ruby-lang.org/issues/14799#change-72313
* Author: zverok (Victor Shepelev)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
----------------------------------------
On introduction of endless range at #12912, "startless range" was discussed this way:
> @sowieso: Not having the opposite (`..5` and `..-2`) feels like this is rather a hack than a thoroughly planned feature.
> @duerst: I don't understand the need for a `..5` Range. The feature is called "endless range". Although mathematically, it's possible to think about startless ranges, they don't work in a program. Maybe some programming languages have `..5` as a shortcut for `0..5`, but that's in any way a usual, bounded, range with a start and an end. It's conceptually totally different from `5..`, which is a range with a start but no end, an unbound range.
In the context of that ticket (ranges used mostly for slicing arrays) having `..5` was indeed hard to justify, but there are other cases when `..5` being `-Infinity..5` is absolutely reasonable:
```ruby
case release_date
when ..1.year.ago
puts "ancient"
when 1.year.ago..3.months.ago
puts "old"
when 3.months.ago..Date.today
puts "recent"
when Date.today..
puts "upcoming"
end
log.map(&:logged_at).grep(..Date.new(1980)) # => outliers due to bad log parsing...
```
E.g., whenever case equality operator is acting, having startless range to express "below this value" is the most concise and readable way. Also, for expressing constants (mostly decorative, but very readable):
```ruby
# Celsius degrees
WORK_RANGES = {
..-10 => :turn_off,
-10..0 => :energy_saving,
0..20 => :main,
20..35 => :cooling,
35.. => :turn_off
}
```
In addition, my related proposal #14784 suggests that this kind of ranges could be utilized by more powerful clamp too:
```ruby
updated_at.clamp(..Date.today)
```
**Uncertainty points:**
* Would it be hard to add to parser? I am not sure, I am not very good at it :(
* Should `..` be a thing? I guess not, unless there would be convincing real-life examples, which for me it is hard to think of.
---Files--------------------------------
beginless-range.patch (3.55 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 16+ messages in thread
* [ruby-core:87388] [Ruby trunk Feature#14799] Startless range
[not found] <redmine.issue-14799.20180531075634@ruby-lang.org>
` (6 preceding siblings ...)
2018-05-31 13:01 ` [ruby-core:87320] [Ruby trunk Feature#14799] " janosch84
@ 2018-06-04 11:10 ` darkwiiplayer
2018-06-14 14:34 ` [ruby-core:87492] " zn
` (7 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: darkwiiplayer @ 2018-06-04 11:10 UTC (permalink / raw)
To: ruby-core
Issue #14799 has been updated by DarkWiiPlayer (Dennis Fischer).
This does make sense when considering the reverse of the range, in other words, counting down from N to -infinity. This reasoning has several problems though:
- Ranges have no method that reverse them
- Ruby doesn't seem to like N..M ranges where M < N (`(5..1).each {|x| puts x}` simply prints `5..1` in ruby 2.5
Intuitively, counting down like that seems like a pretty common use case, but I cannot actually recall ever needing it, and it could also be simulated with a forward-counting range and just multiplying the values with -1 before using them, which shouldn't really have any considerable impact on speed.
----------------------------------------
Feature #14799: Startless range
https://bugs.ruby-lang.org/issues/14799#change-72374
* Author: zverok (Victor Shepelev)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
----------------------------------------
On introduction of endless range at #12912, "startless range" was discussed this way:
> @sowieso: Not having the opposite (`..5` and `..-2`) feels like this is rather a hack than a thoroughly planned feature.
> @duerst: I don't understand the need for a `..5` Range. The feature is called "endless range". Although mathematically, it's possible to think about startless ranges, they don't work in a program. Maybe some programming languages have `..5` as a shortcut for `0..5`, but that's in any way a usual, bounded, range with a start and an end. It's conceptually totally different from `5..`, which is a range with a start but no end, an unbound range.
In the context of that ticket (ranges used mostly for slicing arrays) having `..5` was indeed hard to justify, but there are other cases when `..5` being `-Infinity..5` is absolutely reasonable:
```ruby
case release_date
when ..1.year.ago
puts "ancient"
when 1.year.ago..3.months.ago
puts "old"
when 3.months.ago..Date.today
puts "recent"
when Date.today..
puts "upcoming"
end
log.map(&:logged_at).grep(..Date.new(1980)) # => outliers due to bad log parsing...
```
E.g., whenever case equality operator is acting, having startless range to express "below this value" is the most concise and readable way. Also, for expressing constants (mostly decorative, but very readable):
```ruby
# Celsius degrees
WORK_RANGES = {
..-10 => :turn_off,
-10..0 => :energy_saving,
0..20 => :main,
20..35 => :cooling,
35.. => :turn_off
}
```
In addition, my related proposal #14784 suggests that this kind of ranges could be utilized by more powerful clamp too:
```ruby
updated_at.clamp(..Date.today)
```
**Uncertainty points:**
* Would it be hard to add to parser? I am not sure, I am not very good at it :(
* Should `..` be a thing? I guess not, unless there would be convincing real-life examples, which for me it is hard to think of.
---Files--------------------------------
beginless-range.patch (3.55 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 16+ messages in thread
* [ruby-core:87492] [Ruby trunk Feature#14799] Startless range
[not found] <redmine.issue-14799.20180531075634@ruby-lang.org>
` (7 preceding siblings ...)
2018-06-04 11:10 ` [ruby-core:87388] " darkwiiplayer
@ 2018-06-14 14:34 ` zn
2018-06-14 15:16 ` [ruby-core:87494] " eregontp
` (6 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: zn @ 2018-06-14 14:34 UTC (permalink / raw)
To: ruby-core
Issue #14799 has been updated by znz (Kazuhiro NISHIYAMA).
I think version guard of ruby/spec is one of usages.
For example:
```ruby
ruby_version_is ""..."2.6" do
# ...
end
```
----------------------------------------
Feature #14799: Startless range
https://bugs.ruby-lang.org/issues/14799#change-72496
* Author: zverok (Victor Shepelev)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
----------------------------------------
On introduction of endless range at #12912, "startless range" was discussed this way:
> @sowieso: Not having the opposite (`..5` and `..-2`) feels like this is rather a hack than a thoroughly planned feature.
> @duerst: I don't understand the need for a `..5` Range. The feature is called "endless range". Although mathematically, it's possible to think about startless ranges, they don't work in a program. Maybe some programming languages have `..5` as a shortcut for `0..5`, but that's in any way a usual, bounded, range with a start and an end. It's conceptually totally different from `5..`, which is a range with a start but no end, an unbound range.
In the context of that ticket (ranges used mostly for slicing arrays) having `..5` was indeed hard to justify, but there are other cases when `..5` being `-Infinity..5` is absolutely reasonable:
```ruby
case release_date
when ..1.year.ago
puts "ancient"
when 1.year.ago..3.months.ago
puts "old"
when 3.months.ago..Date.today
puts "recent"
when Date.today..
puts "upcoming"
end
log.map(&:logged_at).grep(..Date.new(1980)) # => outliers due to bad log parsing...
```
E.g., whenever case equality operator is acting, having startless range to express "below this value" is the most concise and readable way. Also, for expressing constants (mostly decorative, but very readable):
```ruby
# Celsius degrees
WORK_RANGES = {
..-10 => :turn_off,
-10..0 => :energy_saving,
0..20 => :main,
20..35 => :cooling,
35.. => :turn_off
}
```
In addition, my related proposal #14784 suggests that this kind of ranges could be utilized by more powerful clamp too:
```ruby
updated_at.clamp(..Date.today)
```
**Uncertainty points:**
* Would it be hard to add to parser? I am not sure, I am not very good at it :(
* Should `..` be a thing? I guess not, unless there would be convincing real-life examples, which for me it is hard to think of.
---Files--------------------------------
beginless-range.patch (3.55 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 16+ messages in thread
* [ruby-core:87494] [Ruby trunk Feature#14799] Startless range
[not found] <redmine.issue-14799.20180531075634@ruby-lang.org>
` (8 preceding siblings ...)
2018-06-14 14:34 ` [ruby-core:87492] " zn
@ 2018-06-14 15:16 ` eregontp
2018-06-14 22:30 ` [ruby-core:87496] " mame
` (5 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: eregontp @ 2018-06-14 15:16 UTC (permalink / raw)
To: ruby-core
Issue #14799 has been updated by Eregon (Benoit Daloze).
znz (Kazuhiro NISHIYAMA) wrote:
> I think version guard of ruby/spec is one of usages.
>
> For example:
>
> ```ruby
> ruby_version_is ""..."2.6" do
> # ...
> end
> ```
Right, this would be a nice way to express version ranges like
~~~ ruby
ruby_version_is ..."2.6" do
# ...
end
ruby_version_is "2.4"... do
# ...
end
~~~
However for the case of ruby/spec, we'll have to wait until 2.5 is out of life to actually use those, as the syntax does not work on 2.5 and earlier.
----------------------------------------
Feature #14799: Startless range
https://bugs.ruby-lang.org/issues/14799#change-72498
* Author: zverok (Victor Shepelev)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
----------------------------------------
On introduction of endless range at #12912, "startless range" was discussed this way:
> @sowieso: Not having the opposite (`..5` and `..-2`) feels like this is rather a hack than a thoroughly planned feature.
> @duerst: I don't understand the need for a `..5` Range. The feature is called "endless range". Although mathematically, it's possible to think about startless ranges, they don't work in a program. Maybe some programming languages have `..5` as a shortcut for `0..5`, but that's in any way a usual, bounded, range with a start and an end. It's conceptually totally different from `5..`, which is a range with a start but no end, an unbound range.
In the context of that ticket (ranges used mostly for slicing arrays) having `..5` was indeed hard to justify, but there are other cases when `..5` being `-Infinity..5` is absolutely reasonable:
```ruby
case release_date
when ..1.year.ago
puts "ancient"
when 1.year.ago..3.months.ago
puts "old"
when 3.months.ago..Date.today
puts "recent"
when Date.today..
puts "upcoming"
end
log.map(&:logged_at).grep(..Date.new(1980)) # => outliers due to bad log parsing...
```
E.g., whenever case equality operator is acting, having startless range to express "below this value" is the most concise and readable way. Also, for expressing constants (mostly decorative, but very readable):
```ruby
# Celsius degrees
WORK_RANGES = {
..-10 => :turn_off,
-10..0 => :energy_saving,
0..20 => :main,
20..35 => :cooling,
35.. => :turn_off
}
```
In addition, my related proposal #14784 suggests that this kind of ranges could be utilized by more powerful clamp too:
```ruby
updated_at.clamp(..Date.today)
```
**Uncertainty points:**
* Would it be hard to add to parser? I am not sure, I am not very good at it :(
* Should `..` be a thing? I guess not, unless there would be convincing real-life examples, which for me it is hard to think of.
---Files--------------------------------
beginless-range.patch (3.55 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 16+ messages in thread
* [ruby-core:87496] [Ruby trunk Feature#14799] Startless range
[not found] <redmine.issue-14799.20180531075634@ruby-lang.org>
` (9 preceding siblings ...)
2018-06-14 15:16 ` [ruby-core:87494] " eregontp
@ 2018-06-14 22:30 ` mame
2018-06-15 17:14 ` [ruby-core:87500] " eregontp
` (4 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: mame @ 2018-06-14 22:30 UTC (permalink / raw)
To: ruby-core
Issue #14799 has been updated by mame (Yusuke Endoh).
I agree that it is a good use case.
But notice that we will not be able to write `ruby_version_is ..."2.6" do` because it parses as `(ruby_version_is..."2.6") do`.
We need to write parentheses: `ruby_version_is(..."2.6") do`.
----------------------------------------
Feature #14799: Startless range
https://bugs.ruby-lang.org/issues/14799#change-72500
* Author: zverok (Victor Shepelev)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
----------------------------------------
On introduction of endless range at #12912, "startless range" was discussed this way:
> @sowieso: Not having the opposite (`..5` and `..-2`) feels like this is rather a hack than a thoroughly planned feature.
> @duerst: I don't understand the need for a `..5` Range. The feature is called "endless range". Although mathematically, it's possible to think about startless ranges, they don't work in a program. Maybe some programming languages have `..5` as a shortcut for `0..5`, but that's in any way a usual, bounded, range with a start and an end. It's conceptually totally different from `5..`, which is a range with a start but no end, an unbound range.
In the context of that ticket (ranges used mostly for slicing arrays) having `..5` was indeed hard to justify, but there are other cases when `..5` being `-Infinity..5` is absolutely reasonable:
```ruby
case release_date
when ..1.year.ago
puts "ancient"
when 1.year.ago..3.months.ago
puts "old"
when 3.months.ago..Date.today
puts "recent"
when Date.today..
puts "upcoming"
end
log.map(&:logged_at).grep(..Date.new(1980)) # => outliers due to bad log parsing...
```
E.g., whenever case equality operator is acting, having startless range to express "below this value" is the most concise and readable way. Also, for expressing constants (mostly decorative, but very readable):
```ruby
# Celsius degrees
WORK_RANGES = {
..-10 => :turn_off,
-10..0 => :energy_saving,
0..20 => :main,
20..35 => :cooling,
35.. => :turn_off
}
```
In addition, my related proposal #14784 suggests that this kind of ranges could be utilized by more powerful clamp too:
```ruby
updated_at.clamp(..Date.today)
```
**Uncertainty points:**
* Would it be hard to add to parser? I am not sure, I am not very good at it :(
* Should `..` be a thing? I guess not, unless there would be convincing real-life examples, which for me it is hard to think of.
---Files--------------------------------
beginless-range.patch (3.55 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 16+ messages in thread
* [ruby-core:87500] [Ruby trunk Feature#14799] Startless range
[not found] <redmine.issue-14799.20180531075634@ruby-lang.org>
` (10 preceding siblings ...)
2018-06-14 22:30 ` [ruby-core:87496] " mame
@ 2018-06-15 17:14 ` eregontp
2018-06-21 9:02 ` [ruby-core:87561] " knu
` (3 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: eregontp @ 2018-06-15 17:14 UTC (permalink / raw)
To: ruby-core
Issue #14799 has been updated by Eregon (Benoit Daloze).
@mame Ah, that is quite unfortunate (it does not look so nice with the parens), but thank you for mentioning the caveat.
I guess much like Range literals in general, it's often needed to have parens around them.
----------------------------------------
Feature #14799: Startless range
https://bugs.ruby-lang.org/issues/14799#change-72506
* Author: zverok (Victor Shepelev)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
----------------------------------------
On introduction of endless range at #12912, "startless range" was discussed this way:
> @sowieso: Not having the opposite (`..5` and `..-2`) feels like this is rather a hack than a thoroughly planned feature.
> @duerst: I don't understand the need for a `..5` Range. The feature is called "endless range". Although mathematically, it's possible to think about startless ranges, they don't work in a program. Maybe some programming languages have `..5` as a shortcut for `0..5`, but that's in any way a usual, bounded, range with a start and an end. It's conceptually totally different from `5..`, which is a range with a start but no end, an unbound range.
In the context of that ticket (ranges used mostly for slicing arrays) having `..5` was indeed hard to justify, but there are other cases when `..5` being `-Infinity..5` is absolutely reasonable:
```ruby
case release_date
when ..1.year.ago
puts "ancient"
when 1.year.ago..3.months.ago
puts "old"
when 3.months.ago..Date.today
puts "recent"
when Date.today..
puts "upcoming"
end
log.map(&:logged_at).grep(..Date.new(1980)) # => outliers due to bad log parsing...
```
E.g., whenever case equality operator is acting, having startless range to express "below this value" is the most concise and readable way. Also, for expressing constants (mostly decorative, but very readable):
```ruby
# Celsius degrees
WORK_RANGES = {
..-10 => :turn_off,
-10..0 => :energy_saving,
0..20 => :main,
20..35 => :cooling,
35.. => :turn_off
}
```
In addition, my related proposal #14784 suggests that this kind of ranges could be utilized by more powerful clamp too:
```ruby
updated_at.clamp(..Date.today)
```
**Uncertainty points:**
* Would it be hard to add to parser? I am not sure, I am not very good at it :(
* Should `..` be a thing? I guess not, unless there would be convincing real-life examples, which for me it is hard to think of.
---Files--------------------------------
beginless-range.patch (3.55 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 16+ messages in thread
* [ruby-core:87561] [Ruby trunk Feature#14799] Startless range
[not found] <redmine.issue-14799.20180531075634@ruby-lang.org>
` (11 preceding siblings ...)
2018-06-15 17:14 ` [ruby-core:87500] " eregontp
@ 2018-06-21 9:02 ` knu
2019-03-11 5:17 ` [ruby-core:91747] " matz
` (2 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: knu @ 2018-06-21 9:02 UTC (permalink / raw)
To: ruby-core
Issue #14799 has been updated by knu (Akinori MUSHA).
Let me point out that with this patch applied, `(nil..nil).cover?(1)` would become returning true rather than raising an error. Note that `nil..nil` has been valid for all past versions of ruby.
----------------------------------------
Feature #14799: Startless range
https://bugs.ruby-lang.org/issues/14799#change-72568
* Author: zverok (Victor Shepelev)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
----------------------------------------
On introduction of endless range at #12912, "startless range" was discussed this way:
> @sowieso: Not having the opposite (`..5` and `..-2`) feels like this is rather a hack than a thoroughly planned feature.
> @duerst: I don't understand the need for a `..5` Range. The feature is called "endless range". Although mathematically, it's possible to think about startless ranges, they don't work in a program. Maybe some programming languages have `..5` as a shortcut for `0..5`, but that's in any way a usual, bounded, range with a start and an end. It's conceptually totally different from `5..`, which is a range with a start but no end, an unbound range.
In the context of that ticket (ranges used mostly for slicing arrays) having `..5` was indeed hard to justify, but there are other cases when `..5` being `-Infinity..5` is absolutely reasonable:
```ruby
case release_date
when ..1.year.ago
puts "ancient"
when 1.year.ago..3.months.ago
puts "old"
when 3.months.ago..Date.today
puts "recent"
when Date.today..
puts "upcoming"
end
log.map(&:logged_at).grep(..Date.new(1980)) # => outliers due to bad log parsing...
```
E.g., whenever case equality operator is acting, having startless range to express "below this value" is the most concise and readable way. Also, for expressing constants (mostly decorative, but very readable):
```ruby
# Celsius degrees
WORK_RANGES = {
..-10 => :turn_off,
-10..0 => :energy_saving,
0..20 => :main,
20..35 => :cooling,
35.. => :turn_off
}
```
In addition, my related proposal #14784 suggests that this kind of ranges could be utilized by more powerful clamp too:
```ruby
updated_at.clamp(..Date.today)
```
**Uncertainty points:**
* Would it be hard to add to parser? I am not sure, I am not very good at it :(
* Should `..` be a thing? I guess not, unless there would be convincing real-life examples, which for me it is hard to think of.
---Files--------------------------------
beginless-range.patch (3.55 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 16+ messages in thread
* [ruby-core:91747] [Ruby trunk Feature#14799] Startless range
[not found] <redmine.issue-14799.20180531075634@ruby-lang.org>
` (12 preceding siblings ...)
2018-06-21 9:02 ` [ruby-core:87561] " knu
@ 2019-03-11 5:17 ` matz
2019-03-11 5:29 ` [ruby-core:91749] " nobu
2019-04-03 8:16 ` [ruby-core:92123] " mame
15 siblings, 0 replies; 16+ messages in thread
From: matz @ 2019-03-11 5:17 UTC (permalink / raw)
To: ruby-core
Issue #14799 has been updated by matz (Yukihiro Matsumoto).
I have some concerns, especially ones with syntax rules. Let us try it in the trunk, and see if it works well or not.
Matz.
----------------------------------------
Feature #14799: Startless range
https://bugs.ruby-lang.org/issues/14799#change-77023
* Author: zverok (Victor Shepelev)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
----------------------------------------
On introduction of endless range at #12912, "startless range" was discussed this way:
> @sowieso: Not having the opposite (`..5` and `..-2`) feels like this is rather a hack than a thoroughly planned feature.
> @duerst: I don't understand the need for a `..5` Range. The feature is called "endless range". Although mathematically, it's possible to think about startless ranges, they don't work in a program. Maybe some programming languages have `..5` as a shortcut for `0..5`, but that's in any way a usual, bounded, range with a start and an end. It's conceptually totally different from `5..`, which is a range with a start but no end, an unbound range.
In the context of that ticket (ranges used mostly for slicing arrays) having `..5` was indeed hard to justify, but there are other cases when `..5` being `-Infinity..5` is absolutely reasonable:
```ruby
case release_date
when ..1.year.ago
puts "ancient"
when 1.year.ago..3.months.ago
puts "old"
when 3.months.ago..Date.today
puts "recent"
when Date.today..
puts "upcoming"
end
log.map(&:logged_at).grep(..Date.new(1980)) # => outliers due to bad log parsing...
```
E.g., whenever case equality operator is acting, having startless range to express "below this value" is the most concise and readable way. Also, for expressing constants (mostly decorative, but very readable):
```ruby
# Celsius degrees
WORK_RANGES = {
..-10 => :turn_off,
-10..0 => :energy_saving,
0..20 => :main,
20..35 => :cooling,
35.. => :turn_off
}
```
In addition, my related proposal #14784 suggests that this kind of ranges could be utilized by more powerful clamp too:
```ruby
updated_at.clamp(..Date.today)
```
**Uncertainty points:**
* Would it be hard to add to parser? I am not sure, I am not very good at it :(
* Should `..` be a thing? I guess not, unless there would be convincing real-life examples, which for me it is hard to think of.
---Files--------------------------------
beginless-range.patch (3.55 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 16+ messages in thread
* [ruby-core:91749] [Ruby trunk Feature#14799] Startless range
[not found] <redmine.issue-14799.20180531075634@ruby-lang.org>
` (13 preceding siblings ...)
2019-03-11 5:17 ` [ruby-core:91747] " matz
@ 2019-03-11 5:29 ` nobu
2019-04-03 8:16 ` [ruby-core:92123] " mame
15 siblings, 0 replies; 16+ messages in thread
From: nobu @ 2019-03-11 5:29 UTC (permalink / raw)
To: ruby-core
Issue #14799 has been updated by nobu (Nobuyoshi Nakada).
`BDOT2` and `BDOT3` don't seem necessary.
----------------------------------------
Feature #14799: Startless range
https://bugs.ruby-lang.org/issues/14799#change-77025
* Author: zverok (Victor Shepelev)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
----------------------------------------
On introduction of endless range at #12912, "startless range" was discussed this way:
> @sowieso: Not having the opposite (`..5` and `..-2`) feels like this is rather a hack than a thoroughly planned feature.
> @duerst: I don't understand the need for a `..5` Range. The feature is called "endless range". Although mathematically, it's possible to think about startless ranges, they don't work in a program. Maybe some programming languages have `..5` as a shortcut for `0..5`, but that's in any way a usual, bounded, range with a start and an end. It's conceptually totally different from `5..`, which is a range with a start but no end, an unbound range.
In the context of that ticket (ranges used mostly for slicing arrays) having `..5` was indeed hard to justify, but there are other cases when `..5` being `-Infinity..5` is absolutely reasonable:
```ruby
case release_date
when ..1.year.ago
puts "ancient"
when 1.year.ago..3.months.ago
puts "old"
when 3.months.ago..Date.today
puts "recent"
when Date.today..
puts "upcoming"
end
log.map(&:logged_at).grep(..Date.new(1980)) # => outliers due to bad log parsing...
```
E.g., whenever case equality operator is acting, having startless range to express "below this value" is the most concise and readable way. Also, for expressing constants (mostly decorative, but very readable):
```ruby
# Celsius degrees
WORK_RANGES = {
..-10 => :turn_off,
-10..0 => :energy_saving,
0..20 => :main,
20..35 => :cooling,
35.. => :turn_off
}
```
In addition, my related proposal #14784 suggests that this kind of ranges could be utilized by more powerful clamp too:
```ruby
updated_at.clamp(..Date.today)
```
**Uncertainty points:**
* Would it be hard to add to parser? I am not sure, I am not very good at it :(
* Should `..` be a thing? I guess not, unless there would be convincing real-life examples, which for me it is hard to think of.
---Files--------------------------------
beginless-range.patch (3.55 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 16+ messages in thread
* [ruby-core:92123] [Ruby trunk Feature#14799] Startless range
[not found] <redmine.issue-14799.20180531075634@ruby-lang.org>
` (14 preceding siblings ...)
2019-03-11 5:29 ` [ruby-core:91749] " nobu
@ 2019-04-03 8:16 ` mame
15 siblings, 0 replies; 16+ messages in thread
From: mame @ 2019-04-03 8:16 UTC (permalink / raw)
To: ruby-core
Issue #14799 has been updated by mame (Yusuke Endoh).
Status changed from Assigned to Closed
Committed at r67422. Please give it a try and let me know if you find any issue.
----------------------------------------
Feature #14799: Startless range
https://bugs.ruby-lang.org/issues/14799#change-77449
* Author: zverok (Victor Shepelev)
* Status: Closed
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
----------------------------------------
On introduction of endless range at #12912, "startless range" was discussed this way:
> @sowieso: Not having the opposite (`..5` and `..-2`) feels like this is rather a hack than a thoroughly planned feature.
> @duerst: I don't understand the need for a `..5` Range. The feature is called "endless range". Although mathematically, it's possible to think about startless ranges, they don't work in a program. Maybe some programming languages have `..5` as a shortcut for `0..5`, but that's in any way a usual, bounded, range with a start and an end. It's conceptually totally different from `5..`, which is a range with a start but no end, an unbound range.
In the context of that ticket (ranges used mostly for slicing arrays) having `..5` was indeed hard to justify, but there are other cases when `..5` being `-Infinity..5` is absolutely reasonable:
```ruby
case release_date
when ..1.year.ago
puts "ancient"
when 1.year.ago..3.months.ago
puts "old"
when 3.months.ago..Date.today
puts "recent"
when Date.today..
puts "upcoming"
end
log.map(&:logged_at).grep(..Date.new(1980)) # => outliers due to bad log parsing...
```
E.g., whenever case equality operator is acting, having startless range to express "below this value" is the most concise and readable way. Also, for expressing constants (mostly decorative, but very readable):
```ruby
# Celsius degrees
WORK_RANGES = {
..-10 => :turn_off,
-10..0 => :energy_saving,
0..20 => :main,
20..35 => :cooling,
35.. => :turn_off
}
```
In addition, my related proposal #14784 suggests that this kind of ranges could be utilized by more powerful clamp too:
```ruby
updated_at.clamp(..Date.today)
```
**Uncertainty points:**
* Would it be hard to add to parser? I am not sure, I am not very good at it :(
* Should `..` be a thing? I guess not, unless there would be convincing real-life examples, which for me it is hard to think of.
---Files--------------------------------
beginless-range.patch (3.55 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 16+ messages in thread