ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:81426] [Ruby trunk Feature#13606] Enumerator equality and comparison
       [not found] <redmine.issue-13606.20170527232245@ruby-lang.org>
@ 2017-05-27 23:22 ` glex.spb
  2017-05-28  8:29 ` [ruby-core:81433] [Ruby trunk Feature#13606][Feedback] " duerst
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: glex.spb @ 2017-05-27 23:22 UTC (permalink / raw
  To: ruby-core

Issue #13606 has been reported by glebm (Gleb Mazovetskiy).

----------------------------------------
Feature #13606: Enumerator equality and comparison
https://bugs.ruby-lang.org/issues/13606

* Author: glebm (Gleb Mazovetskiy)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
In Ruby, most objects are compared by value. What do you think about `Enumerator`s following the same pattern? I think this would greatly increase the expressiveness of Ruby.

Proposal:

Two `Enumerator`s should be considered equal (`==`) if they yield the same number of elements and these elements are equal (`==`).
If both of the `Enumerator`s are infinite, the equality operator never terminates.
`<=>` should be handled similarly.



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

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

* [ruby-core:81433] [Ruby trunk Feature#13606][Feedback] Enumerator equality and comparison
       [not found] <redmine.issue-13606.20170527232245@ruby-lang.org>
  2017-05-27 23:22 ` [ruby-core:81426] [Ruby trunk Feature#13606] Enumerator equality and comparison glex.spb
@ 2017-05-28  8:29 ` duerst
  2017-05-28 14:01 ` [ruby-core:81435] [Ruby trunk Feature#13606] " shevegen
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: duerst @ 2017-05-28  8:29 UTC (permalink / raw
  To: ruby-core

Issue #13606 has been updated by duerst (Martin Dürst).

Status changed from Open to Feedback

Sounds interesting in theory, but do you have actual use cases? And do you think that the potential inefficiency is worth it?

----------------------------------------
Feature #13606: Enumerator equality and comparison
https://bugs.ruby-lang.org/issues/13606#change-65138

* Author: glebm (Gleb Mazovetskiy)
* Status: Feedback
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
In Ruby, most objects are compared by value. What do you think about `Enumerator`s following the same pattern? I think this would greatly increase the expressiveness of Ruby.

Proposal:

Two `Enumerator`s should be considered equal (`==`) if they yield the same number of elements and these elements are equal (`==`).
If both of the `Enumerator`s are infinite, the equality operator never terminates.
`<=>` should be handled similarly.



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

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

* [ruby-core:81435] [Ruby trunk Feature#13606] Enumerator equality and comparison
       [not found] <redmine.issue-13606.20170527232245@ruby-lang.org>
  2017-05-27 23:22 ` [ruby-core:81426] [Ruby trunk Feature#13606] Enumerator equality and comparison glex.spb
  2017-05-28  8:29 ` [ruby-core:81433] [Ruby trunk Feature#13606][Feedback] " duerst
@ 2017-05-28 14:01 ` shevegen
  2017-05-28 16:50 ` [ruby-core:81437] " glex.spb
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: shevegen @ 2017-05-28 14:01 UTC (permalink / raw
  To: ruby-core

Issue #13606 has been updated by shevegen (Robert A. Heiler).


I am not even sure that I understand the proposal.

If I understood it correctly then two enumerable objects (did I get this part right)
should return true if they behave/return the same? I think I can see it being 
related to duck typing... but they are not entirely the same are they? Different
object id for most objects for example. But it also may be that I did not fully
understand the proposal yet.

What would the speed penalty be if one exists? I guess the latter one could be
handled by some "behavioural switch" for people who need the behaviour
desscribed in the proposal, so a use-case example would be helpful.

----------------------------------------
Feature #13606: Enumerator equality and comparison
https://bugs.ruby-lang.org/issues/13606#change-65140

* Author: glebm (Gleb Mazovetskiy)
* Status: Feedback
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
In Ruby, most objects are compared by value. What do you think about `Enumerator`s following the same pattern? I think this would greatly increase the expressiveness of Ruby.

Proposal:

Two `Enumerator`s should be considered equal (`==`) if they yield the same number of elements and these elements are equal (`==`).
If both of the `Enumerator`s are infinite, the equality operator never terminates.
`<=>` should be handled similarly.



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

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

* [ruby-core:81437] [Ruby trunk Feature#13606] Enumerator equality and comparison
       [not found] <redmine.issue-13606.20170527232245@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2017-05-28 14:01 ` [ruby-core:81435] [Ruby trunk Feature#13606] " shevegen
@ 2017-05-28 16:50 ` glex.spb
  2017-05-28 16:55 ` [ruby-core:81438] " glex.spb
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: glex.spb @ 2017-05-28 16:50 UTC (permalink / raw
  To: ruby-core

Issue #13606 has been updated by glebm (Gleb Mazovetskiy).


shevegen (Robert A. Heiler) wrote:

> [...] but they are not entirely the same are they? Different
> object id for most objects for example. But it also may be that I did not fully
> understand the proposal yet.

Most objects in Ruby are compared semantically even if the object IDs are different, including `Array` and `Hash`.

> What would the speed penalty be if one exists?

If the `Enumerator`s have different `object_id`s, previous the equality check was `O(1)` but is `O(n)` with this proposal (just like for `Array`).

> I guess the latter one could be
> handled by some "behavioural switch" for people who need the behaviour
> desscribed in the proposal, so a use-case example would be helpful.


I am not proposing a behavioural switch. This should be a backwards-incompatible change.
Use cases are the same as for arrays, except when the "arrays" are "lazy".

Example:

~~~ ruby
[1, 2, 3].reverse == [3, 2, 1]
#=> true

[1, 2, 3].reverse_each == [3, 2, 1]
#=> false

[1, 2, 3].reverse_each == [1, 2, 3].reverse_each
#=> false
~~~

With this proposal, the last two are also `true`.


----------------------------------------
Feature #13606: Enumerator equality and comparison
https://bugs.ruby-lang.org/issues/13606#change-65141

* Author: glebm (Gleb Mazovetskiy)
* Status: Feedback
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
In Ruby, most objects are compared by value. What do you think about `Enumerator`s following the same pattern? I think this would greatly increase the expressiveness of Ruby.

Proposal:

Two `Enumerator`s should be considered equal (`==`) if they yield the same number of elements and these elements are equal (`==`).
If both of the `Enumerator`s are infinite, the equality operator never terminates.
`<=>` should be handled similarly.



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

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

* [ruby-core:81438] [Ruby trunk Feature#13606] Enumerator equality and comparison
       [not found] <redmine.issue-13606.20170527232245@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2017-05-28 16:50 ` [ruby-core:81437] " glex.spb
@ 2017-05-28 16:55 ` glex.spb
  2017-05-28 18:21 ` [ruby-core:81439] " Greg.mpls
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: glex.spb @ 2017-05-28 16:55 UTC (permalink / raw
  To: ruby-core

Issue #13606 has been updated by glebm (Gleb Mazovetskiy).


duerst (Martin Dürst) wrote:
> Sounds interesting in theory, but do you have actual use cases? And do you think that the potential inefficiency is worth it?

The use cases are the same as for comparing `Array`s.
The potential inefficiency is not a problem because if you need to compare `Enumerator`s by `object_id` you can do it using `equal?`. If the `object_id`s are the same, both the current and the proposed comparisons take constant time.

----------------------------------------
Feature #13606: Enumerator equality and comparison
https://bugs.ruby-lang.org/issues/13606#change-65142

* Author: glebm (Gleb Mazovetskiy)
* Status: Feedback
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
In Ruby, most objects are compared by value. What do you think about `Enumerator`s following the same pattern? I think this would greatly increase the expressiveness of Ruby.

Proposal:

Two `Enumerator`s should be considered equal (`==`) if they yield the same number of elements and these elements are equal (`==`).
If both of the `Enumerator`s are infinite, the equality operator never terminates.
`<=>` should be handled similarly.



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

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

* [ruby-core:81439] [Ruby trunk Feature#13606] Enumerator equality and comparison
       [not found] <redmine.issue-13606.20170527232245@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2017-05-28 16:55 ` [ruby-core:81438] " glex.spb
@ 2017-05-28 18:21 ` Greg.mpls
  2017-05-28 19:48 ` [ruby-core:81441] " glex.spb
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: Greg.mpls @ 2017-05-28 18:21 UTC (permalink / raw
  To: ruby-core

Issue #13606 has been updated by MSP-Greg (Greg L).


Could be helpful, but some `Enumerators` are not ordered.  So how would `==` work for 'hash like' objects (assuming they're not based on a hash, which has an `==` operator)?

I suppose it could be considered 'restricted' to ordered collections...

----------------------------------------
Feature #13606: Enumerator equality and comparison
https://bugs.ruby-lang.org/issues/13606#change-65143

* Author: glebm (Gleb Mazovetskiy)
* Status: Feedback
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
In Ruby, most objects are compared by value. What do you think about `Enumerator`s following the same pattern? I think this would greatly increase the expressiveness of Ruby.

Proposal:

Two `Enumerator`s should be considered equal (`==`) if they yield the same number of elements and these elements are equal (`==`).
If both of the `Enumerator`s are infinite, the equality operator never terminates.
`<=>` should be handled similarly.



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

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

* [ruby-core:81441] [Ruby trunk Feature#13606] Enumerator equality and comparison
       [not found] <redmine.issue-13606.20170527232245@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2017-05-28 18:21 ` [ruby-core:81439] " Greg.mpls
@ 2017-05-28 19:48 ` glex.spb
  2017-05-29  7:13 ` [ruby-core:81445] " duerst
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: glex.spb @ 2017-05-28 19:48 UTC (permalink / raw
  To: ruby-core

Issue #13606 has been updated by glebm (Gleb Mazovetskiy).


MSP-Greg (Greg L) wrote:
> Could be helpful, but some `Enumerators` are not ordered.  So how would `==` work for 'hash like' objects (assuming they're not based on a hash, which has an `==` operator)?
> 
> I suppose it could be considered 'restricted' to ordered collections...

Equal objects should produce equal results when used.
From this perspective on equality, enumerators that yield in different order should not be considered equal, even if they internally yield elements from an unordered collection.

If the enumerator yields in a different order every time it's called, then the comparison is not guaranteed to return the same result every time. This is a rare edge case though.

----------------------------------------
Feature #13606: Enumerator equality and comparison
https://bugs.ruby-lang.org/issues/13606#change-65145

* Author: glebm (Gleb Mazovetskiy)
* Status: Feedback
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
In Ruby, most objects are compared by value. What do you think about `Enumerator`s following the same pattern? I think this would greatly increase the expressiveness of Ruby.

Proposal:

Two `Enumerator`s should be considered equal (`==`) if they yield the same number of elements and these elements are equal (`==`).
If both of the `Enumerator`s are infinite, the equality operator never terminates.
`<=>` should be handled similarly.



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

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

* [ruby-core:81445] [Ruby trunk Feature#13606] Enumerator equality and comparison
       [not found] <redmine.issue-13606.20170527232245@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2017-05-28 19:48 ` [ruby-core:81441] " glex.spb
@ 2017-05-29  7:13 ` duerst
  2017-05-29 14:50 ` [ruby-core:81453] " glex.spb
  2017-08-31  7:36 ` [ruby-core:82569] [Ruby trunk Feature#13606][Rejected] " knu
  9 siblings, 0 replies; 10+ messages in thread
From: duerst @ 2017-05-29  7:13 UTC (permalink / raw
  To: ruby-core

Issue #13606 has been updated by duerst (Martin Dürst).


MSP-Greg (Greg L) wrote:
> Could be helpful, but some `Enumerators` are not ordered.

All `Enumerators` are ordered. The order is defined by the `each` method, or alternatively by the `to_a` method.

Actually, I wonder if there's any difference between what the OP wants and

```
enumerator_A.to_a == enumerator_B.to_a
```

Although direct comparison for equality would be shorter, the above makes it explicit that efficiency may be low.

----------------------------------------
Feature #13606: Enumerator equality and comparison
https://bugs.ruby-lang.org/issues/13606#change-65150

* Author: glebm (Gleb Mazovetskiy)
* Status: Feedback
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
In Ruby, most objects are compared by value. What do you think about `Enumerator`s following the same pattern? I think this would greatly increase the expressiveness of Ruby.

Proposal:

Two `Enumerator`s should be considered equal (`==`) if they yield the same number of elements and these elements are equal (`==`).
If both of the `Enumerator`s are infinite, the equality operator never terminates.
`<=>` should be handled similarly.



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

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

* [ruby-core:81453] [Ruby trunk Feature#13606] Enumerator equality and comparison
       [not found] <redmine.issue-13606.20170527232245@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2017-05-29  7:13 ` [ruby-core:81445] " duerst
@ 2017-05-29 14:50 ` glex.spb
  2017-08-31  7:36 ` [ruby-core:82569] [Ruby trunk Feature#13606][Rejected] " knu
  9 siblings, 0 replies; 10+ messages in thread
From: glex.spb @ 2017-05-29 14:50 UTC (permalink / raw
  To: ruby-core

Issue #13606 has been updated by glebm (Gleb Mazovetskiy).


duerst (Martin Dürst) wrote:
 
> Actually, I wonder if there's any difference between what the OP wants and
> 
> ```
> enumerator_A.to_a == enumerator_B.to_a
> ```

The above allocates Arrays, Enumerator equality would not.

----------------------------------------
Feature #13606: Enumerator equality and comparison
https://bugs.ruby-lang.org/issues/13606#change-65155

* Author: glebm (Gleb Mazovetskiy)
* Status: Feedback
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
In Ruby, most objects are compared by value. What do you think about `Enumerator`s following the same pattern? I think this would greatly increase the expressiveness of Ruby.

Proposal:

Two `Enumerator`s should be considered equal (`==`) if they yield the same number of elements and these elements are equal (`==`).
If both of the `Enumerator`s are infinite, the equality operator never terminates.
`<=>` should be handled similarly.



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

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

* [ruby-core:82569] [Ruby trunk Feature#13606][Rejected] Enumerator equality and comparison
       [not found] <redmine.issue-13606.20170527232245@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2017-05-29 14:50 ` [ruby-core:81453] " glex.spb
@ 2017-08-31  7:36 ` knu
  9 siblings, 0 replies; 10+ messages in thread
From: knu @ 2017-08-31  7:36 UTC (permalink / raw
  To: ruby-core

Issue #13606 has been updated by knu (Akinori MUSHA).

Status changed from Feedback to Rejected

Without any actual use case, there would be no effective definition of equality for enumerators.

FWIW, the initial design policy is, Enumerator is an abstract entity that only guarantees it responds to `each` for enumeration, and it's not your problem as to what's behind a given enumerator.  You shouldn't have to care about the equality in the first place.

----------------------------------------
Feature #13606: Enumerator equality and comparison
https://bugs.ruby-lang.org/issues/13606#change-66387

* Author: glebm (Gleb Mazovetskiy)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
In Ruby, most objects are compared by value. What do you think about `Enumerator`s following the same pattern? I think this would greatly increase the expressiveness of Ruby.

Proposal:

Two `Enumerator`s should be considered equal (`==`) if they yield the same number of elements and these elements are equal (`==`).
If both of the `Enumerator`s are infinite, the equality operator never terminates.
`<=>` should be handled similarly.



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

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

end of thread, other threads:[~2017-08-31  7:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-13606.20170527232245@ruby-lang.org>
2017-05-27 23:22 ` [ruby-core:81426] [Ruby trunk Feature#13606] Enumerator equality and comparison glex.spb
2017-05-28  8:29 ` [ruby-core:81433] [Ruby trunk Feature#13606][Feedback] " duerst
2017-05-28 14:01 ` [ruby-core:81435] [Ruby trunk Feature#13606] " shevegen
2017-05-28 16:50 ` [ruby-core:81437] " glex.spb
2017-05-28 16:55 ` [ruby-core:81438] " glex.spb
2017-05-28 18:21 ` [ruby-core:81439] " Greg.mpls
2017-05-28 19:48 ` [ruby-core:81441] " glex.spb
2017-05-29  7:13 ` [ruby-core:81445] " duerst
2017-05-29 14:50 ` [ruby-core:81453] " glex.spb
2017-08-31  7:36 ` [ruby-core:82569] [Ruby trunk Feature#13606][Rejected] " knu

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).