https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112012-12-23T18:33:37ZRuby Issue Tracking SystemRuby master - Feature #7604: Make === comparison operator ability to delegate comparison to an argumenthttps://bugs.ruby-lang.org/issues/7604?journal_id=350252012-12-23T18:33:37ZAnonymous
<ul></ul><p>Your proposal reminds me of trying to extend #coerce behavior. What you call "mirroring", happens with #coerce. "Double mirrorring" is prevented by simply by #coerce being required to return a compatible pair. That being said, I did have times, when I wanted operator-specific #coerce (eg. different physical quantities do not add or compare, but do multiply). Essentially, you are proposing:</p>
<p>(1.) Let us have operator-specific #coerce (for #=== at least).<br>
(2.) Let us have #=== actually using its specific coerce for some chosen argument types.</p>
<p>To me, achieving (1.) is imaginable as either #coerce taking an optional second argument, as in other.coerce( self, :=== ), or as having special #coerce_plus, #coerce_asterisk, #coerce_double_equal_sign, #coerce_triple_equal_sign etc.</p>
<p>Achieving (2.) is more difficult. As you pointed out, many classes have their own #===. But it is a general case that operator methods should be written with #coerce in mind.</p>
<p>Having thus reframed your proposal, let me also express my personal opinion about it: I would be in favor of cautiously implementing (1.), while (2.) means a bit work for everyone. I noticed that Marc Andre was also concerned about #coerce specification.</p> Ruby master - Feature #7604: Make === comparison operator ability to delegate comparison to an argumenthttps://bugs.ruby-lang.org/issues/7604?journal_id=350292012-12-24T00:49:10Zprijutme4ty (Ilya Vorontsov)prijutme4ty@gmail.com
<ul></ul><p>boris_stitnicky (Boris Stitnicky) wrote:</p>
<blockquote>
<p>Your proposal reminds me of trying to extend #coerce behavior. What you call "mirroring", happens with #coerce. "Double mirrorring" is prevented by simply by #coerce being required to return a compatible pair. That being said, I did have times, when I wanted operator-specific #coerce (eg. different physical quantities do not add or compare, but do multiply). Essentially, you are proposing:</p>
<p>(1.) Let us have operator-specific #coerce (for #=== at least).<br>
(2.) Let us have #=== actually using its specific coerce for some chosen argument types.</p>
<p>To me, achieving (1.) is imaginable as either #coerce taking an optional second argument, as in other.coerce( self, :=== ), or as having special #coerce_plus, #coerce_asterisk, #coerce_double_equal_sign, #coerce_triple_equal_sign etc.</p>
<p>Achieving (2.) is more difficult. As you pointed out, many classes have their own #===. But it is a general case that operator methods should be written with #coerce in mind.</p>
<p>Having thus reframed your proposal, let me also express my personal opinion about it: I would be in favor of cautiously implementing (1.), while (2.) means a bit work for everyone. I noticed that Marc Andre was also concerned about #coerce specification.</p>
</blockquote>
<p>I like the idea of #coerce having additional argument(first time I thought whether current behavior of coerce can help me in solving this problem). Coercion implies that code of operators like + or === in built-in should be changed as in (2) case. I think that your solution can be actually much more flexible than mine. Also I can't realize any benefits of (2) over (1).</p> Ruby master - Feature #7604: Make === comparison operator ability to delegate comparison to an argumenthttps://bugs.ruby-lang.org/issues/7604?journal_id=350502012-12-25T03:49:18ZAnonymous
<ul></ul><p>(2) and (1) are two steps of the same campaign, to make the behavior you described possible, but (1) might be easier and mildly useful on its own. Current #coerce would solve the problem provided that you make it return special objects with customized multiple operator methods, similar to your Predicate. Why not make a coerce-based gem demonstrating this? I would be interested in using it personally. You would have to find and patch those scattered #=== methods, while I am more interested in :+, :-, :*, :/, :**, and :<=>. We could have common special object for all of these.</p> Ruby master - Feature #7604: Make === comparison operator ability to delegate comparison to an argumenthttps://bugs.ruby-lang.org/issues/7604?journal_id=350792012-12-26T11:33:09Zprijutme4ty (Ilya Vorontsov)prijutme4ty@gmail.com
<ul></ul><p>boris_stitnicky (Boris Stitnicky) wrote:</p>
<blockquote>
<p>(2) and (1) are two steps of the same campaign, to make the behavior you described possible, but (1) might be easier and mildly useful on its own. Current #coerce would solve the problem provided that you make it return special objects with customized multiple operator methods, similar to your Predicate. Why not make a coerce-based gem demonstrating this? I would be interested in using it personally. You would have to find and patch those scattered #=== methods, while I am more interested in :+, :-, :*, :/, :**, and :<=>. We could have common special object for all of these.</p>
</blockquote>
<p>I will create a proof-of-concept gem, but not sure that I'll be able to create a native extension. So arithmetical operations can become much slower.</p> Ruby master - Feature #7604: Make === comparison operator ability to delegate comparison to an argumenthttps://bugs.ruby-lang.org/issues/7604?journal_id=350922012-12-26T22:38:14ZAnonymous
<ul></ul><p>Let me know when you make the first commit.</p> Ruby master - Feature #7604: Make === comparison operator ability to delegate comparison to an argumenthttps://bugs.ruby-lang.org/issues/7604?journal_id=356112013-01-25T12:52:42Zko1 (Koichi Sasada)
<ul><li><strong>Category</strong> set to <i>core</i></li><li><strong>Target version</strong> set to <i>2.6</i></li></ul> Ruby master - Feature #7604: Make === comparison operator ability to delegate comparison to an argumenthttps://bugs.ruby-lang.org/issues/7604?journal_id=367472013-02-22T09:22:00Zko1 (Koichi Sasada)
<ul><li><strong>Assignee</strong> set to <i>matz (Yukihiro Matsumoto)</i></li></ul> Ruby master - Feature #7604: Make === comparison operator ability to delegate comparison to an argumenthttps://bugs.ruby-lang.org/issues/7604?journal_id=374032013-03-09T06:41:25Zprijutme4ty (Ilya Vorontsov)prijutme4ty@gmail.com
<ul></ul><p>boris_stitnicky (Boris Stitnicky) wrote:</p>
<blockquote>
<p>Let me know when you make the first commit.</p>
</blockquote>
<p>I released proof-of-concept gem. <a href="https://github.com/prijutme4ty/flex_coerce" class="external">https://github.com/prijutme4ty/flex_coerce</a> It makes no changes in behavior of base classes, you need to patch only your own class. But actually I didn't found any use-cases of this (e.g. physical quantities more naturally looks if there is a special quantity representing unity). I hope you'll hint me some good applications of this gem.<br>
It's sad but #=== doesn't use coerce so this gem can't help me solve my task. So I'll soon create another gem that patches === method.</p> Ruby master - Feature #7604: Make === comparison operator ability to delegate comparison to an argumenthttps://bugs.ruby-lang.org/issues/7604?journal_id=375682013-03-13T20:02:06ZAnonymous
<ul></ul><p><a class="user active user-mention" href="https://bugs.ruby-lang.org/users/6075">@ilya (Ilya Boltnev)</a>: I have noticed your post, I'll pay closer attention after next week.</p> Ruby master - Feature #7604: Make === comparison operator ability to delegate comparison to an argumenthttps://bugs.ruby-lang.org/issues/7604?journal_id=384562013-04-12T01:38:47ZAnonymous
<ul></ul><p>I'have started working on it (first I have to handle switch to 2.0 on my machine).</p> Ruby master - Feature #7604: Make === comparison operator ability to delegate comparison to an argumenthttps://bugs.ruby-lang.org/issues/7604?journal_id=384742013-04-12T04:59:46Zheadius (Charles Nutter)headius@headius.com
<ul></ul><p>As a feature that affects all Ruby implementations, this should probably move to CommonRuby: <a href="https://bugs.ruby-lang.org/projects/common-ruby" class="external">https://bugs.ruby-lang.org/projects/common-ruby</a></p> Ruby master - Feature #7604: Make === comparison operator ability to delegate comparison to an argumenthttps://bugs.ruby-lang.org/issues/7604?journal_id=688602017-12-25T18:15:09Znaruse (Yui NARUSE)naruse@airemix.jp
<ul><li><strong>Target version</strong> deleted (<del><i>2.6</i></del>)</li></ul>