[#92070] [Ruby trunk Feature#15667] Introduce malloc_trim(0) in full gc cycles — sam.saffron@...
Issue #15667 has been updated by sam.saffron (Sam Saffron).
3 messages
2019/04/01
[ruby-core:92123] [Ruby trunk Feature#14799] Startless range
From:
mame@...
Date:
2019-04-03 08:16:47 UTC
List:
ruby-core #92123
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/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>