ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:100174] [Ruby master Feature#17195] Freeze Enumerator::ArithmeticSequence objects
@ 2020-09-26 13:20 eregontp
  2020-09-26 18:44 ` [ruby-core:100179] " marcandre-ruby-core
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: eregontp @ 2020-09-26 13:20 UTC (permalink / raw)
  To: ruby-core

Issue #17195 has been reported by Eregon (Benoit Daloze).

----------------------------------------
Feature #17195: Freeze Enumerator::ArithmeticSequence objects
https://bugs.ruby-lang.org/issues/17195

* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
----------------------------------------
Now, all Ranges are frozen (#15504).

Enumerator::ArithmeticSequence is very similar to Range, just with an extra `step`.
They're essentially already immutable, except that one could use set instance variables, but it seems of little use.

So, should we make Enumerator::ArithmeticSequence frozen too?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:100179] [Ruby master Feature#17195] Freeze Enumerator::ArithmeticSequence objects
  2020-09-26 13:20 [ruby-core:100174] [Ruby master Feature#17195] Freeze Enumerator::ArithmeticSequence objects eregontp
@ 2020-09-26 18:44 ` marcandre-ruby-core
  2020-09-27 10:05 ` [ruby-core:100187] " eregontp
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: marcandre-ruby-core @ 2020-09-26 18:44 UTC (permalink / raw)
  To: ruby-core

Issue #17195 has been updated by marcandre (Marc-Andre Lafortune).


Seems clear to me

----------------------------------------
Feature #17195: Freeze Enumerator::ArithmeticSequence objects
https://bugs.ruby-lang.org/issues/17195#change-87752

* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
----------------------------------------
Now, all Ranges are frozen (#15504).

Enumerator::ArithmeticSequence is very similar to Range, just with an extra `step`.
They're essentially already immutable, except that one could use set instance variables, but it seems of little use.

So, should we make Enumerator::ArithmeticSequence frozen too?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:100187] [Ruby master Feature#17195] Freeze Enumerator::ArithmeticSequence objects
  2020-09-26 13:20 [ruby-core:100174] [Ruby master Feature#17195] Freeze Enumerator::ArithmeticSequence objects eregontp
  2020-09-26 18:44 ` [ruby-core:100179] " marcandre-ruby-core
@ 2020-09-27 10:05 ` eregontp
  2020-10-09  8:01 ` [ruby-core:100346] " muraken
  2020-10-09 18:15 ` [ruby-core:100350] " eregontp
  3 siblings, 0 replies; 5+ messages in thread
From: eregontp @ 2020-09-27 10:05 UTC (permalink / raw)
  To: ruby-core

Issue #17195 has been updated by Eregon (Benoit Daloze).


I just realized, this is problematic because `Enumerator::ArithmeticSequence` is a subclass of `Enumerator` and not of `Range`.
If it was a subclass of Range then I think it would be fine to freeze it.

But since it subclasses Enumerator, it has mutably methods like `Enumerator#next`:
```ruby
[7] pry(main)> enum = (1..5).step(2)
=> ((1..5).step(2))
[8] pry(main)> enum.next
=> 1
[9] pry(main)> enum.next
=> 3
[10] pry(main)> enum.next
=> 5
[11] pry(main)> enum.next
StopIteration: iteration reached an end
from (pry):11:in `next'
```

@mrkn do you remember why ArithmeticSequence is an Enumerator subclass and not a Range subclass?

----------------------------------------
Feature #17195: Freeze Enumerator::ArithmeticSequence objects
https://bugs.ruby-lang.org/issues/17195#change-87758

* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
----------------------------------------
Now, all Ranges are frozen (#15504).

Enumerator::ArithmeticSequence is very similar to Range, just with an extra `step`.
They're essentially already immutable, except that one could use set instance variables, but it seems of little use.

So, should we make Enumerator::ArithmeticSequence frozen too?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:100346] [Ruby master Feature#17195] Freeze Enumerator::ArithmeticSequence objects
  2020-09-26 13:20 [ruby-core:100174] [Ruby master Feature#17195] Freeze Enumerator::ArithmeticSequence objects eregontp
  2020-09-26 18:44 ` [ruby-core:100179] " marcandre-ruby-core
  2020-09-27 10:05 ` [ruby-core:100187] " eregontp
@ 2020-10-09  8:01 ` muraken
  2020-10-09 18:15 ` [ruby-core:100350] " eregontp
  3 siblings, 0 replies; 5+ messages in thread
From: muraken @ 2020-10-09  8:01 UTC (permalink / raw)
  To: ruby-core

Issue #17195 has been updated by mrkn (Kenta Murata).


The reason why ArithmeticSequence is a subclass of Enumerator is for conserving the compatibility of the return types of `Range#step` and `Numeric#step`.

----------------------------------------
Feature #17195: Freeze Enumerator::ArithmeticSequence objects
https://bugs.ruby-lang.org/issues/17195#change-87958

* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
----------------------------------------
Now, all Ranges are frozen (#15504).

Enumerator::ArithmeticSequence is very similar to Range, just with an extra `step`.
They're essentially already immutable, except that one could use set instance variables, but it seems of little use.

So, should we make Enumerator::ArithmeticSequence frozen too?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:100350] [Ruby master Feature#17195] Freeze Enumerator::ArithmeticSequence objects
  2020-09-26 13:20 [ruby-core:100174] [Ruby master Feature#17195] Freeze Enumerator::ArithmeticSequence objects eregontp
                   ` (2 preceding siblings ...)
  2020-10-09  8:01 ` [ruby-core:100346] " muraken
@ 2020-10-09 18:15 ` eregontp
  3 siblings, 0 replies; 5+ messages in thread
From: eregontp @ 2020-10-09 18:15 UTC (permalink / raw)
  To: ruby-core

Issue #17195 has been updated by Eregon (Benoit Daloze).

Status changed from Open to Rejected

Right, that makes sense, thanks for the reply.

Interestingly it seems `Enumerator#next` is still allowed even if the Enumerator is frozen, even though it is a kind of mutation.
I think that's a bug.

Given `ArithmeticSequence` has state through being an Enumerator, I think it's not reasonable to freeze, so I'll reject this issue.

----------------------------------------
Feature #17195: Freeze Enumerator::ArithmeticSequence objects
https://bugs.ruby-lang.org/issues/17195#change-87962

* Author: Eregon (Benoit Daloze)
* Status: Rejected
* Priority: Normal
----------------------------------------
Now, all Ranges are frozen (#15504).

Enumerator::ArithmeticSequence is very similar to Range, just with an extra `step`.
They're essentially already immutable, except that one could use set instance variables, but it seems of little use.

So, should we make Enumerator::ArithmeticSequence frozen too?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-10-09 18:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-26 13:20 [ruby-core:100174] [Ruby master Feature#17195] Freeze Enumerator::ArithmeticSequence objects eregontp
2020-09-26 18:44 ` [ruby-core:100179] " marcandre-ruby-core
2020-09-27 10:05 ` [ruby-core:100187] " eregontp
2020-10-09  8:01 ` [ruby-core:100346] " muraken
2020-10-09 18:15 ` [ruby-core:100350] " eregontp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).