https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112012-03-17T00:35:51ZRuby Issue Tracking SystemRuby master - Bug #6159: Enumerable::Lazy#inspecthttps://bugs.ruby-lang.org/issues/6159?journal_id=246532012-03-17T00:35:51Zshugo (Shugo Maeda)
<ul></ul><p>Benoit Daloze wrote:</p>
<blockquote>
<p>So something like: #<Enumerator::Lazy: 1..5:each> or #<Enumerator::Lazy: #<Enumerator: 1..5:each>></p>
<p>It would also be nice to show the chaining, like Enumerator does:</p>
<pre><code>(1..5).select.map.flat_map # => #<Enumerator: #<Enumerator: #<Enumerator: 1..5:select>:map>:flat_map>
</code></pre>
<p>What do you think?</p>
</blockquote>
<p>I agree that It would be nice. However, unlike Enumerator, Enumerator::Lazy doesn't have enough information, so it needs to have some information only for inspect. Is it so important to make inspect rich?</p> Ruby master - Bug #6159: Enumerable::Lazy#inspecthttps://bugs.ruby-lang.org/issues/6159?journal_id=250672012-03-23T18:42:50Zshugo (Shugo Maeda)
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li><li><strong>Assignee</strong> set to <i>shugo (Shugo Maeda)</i></li></ul> Ruby master - Bug #6159: Enumerable::Lazy#inspecthttps://bugs.ruby-lang.org/issues/6159?journal_id=250792012-03-24T20:19:54ZEregon (Benoit Daloze)
<ul></ul><blockquote>
<p>I agree that It would be nice. However, unlike Enumerator, Enumerator::Lazy doesn't have enough information, so it needs to have some information only for inspect.<br>
Is it so important to make inspect rich?</p>
</blockquote>
<p>I'm not sure, but it would certainly be helpful when debugging.<br>
On the other hand, if that would impact significantly performance or code (maintainability), it's probably not worth it.</p>
<p>I guess I'm not used to a core Ruby class without a nice #inspect.</p> Ruby master - Bug #6159: Enumerable::Lazy#inspecthttps://bugs.ruby-lang.org/issues/6159?journal_id=250822012-03-25T00:17:33Zshugo (Shugo Maeda)
<ul><li><strong>Status</strong> changed from <i>Feedback</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>This issue was solved with changeset r35124.<br>
Benoit, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<hr>
<ul>
<li>
<p>enumerator (enumerator_inspect): include the original receiver and<br>
method name of Enumerator::Lazy in the result of inspect.<br>
<a href="/issues/6159">[ruby-core:43345]</a> [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Enumerable::Lazy#inspect (Closed)" href="https://bugs.ruby-lang.org/issues/6159">#6159</a>]</p>
</li>
<li>
<p>enumerator (InitVM_Enumerator): don't use rb_define_alias for<br>
some methods such as collect in order to make rb_frame_this_func()<br>
return the correct method names.</p>
</li>
</ul> Ruby master - Bug #6159: Enumerable::Lazy#inspecthttps://bugs.ruby-lang.org/issues/6159?journal_id=250832012-03-25T00:23:45Zshugo (Shugo Maeda)
<ul></ul><p>Eregon (Benoit Daloze) wrote:</p>
<blockquote>
<blockquote>
<p>I agree that It would be nice. However, unlike Enumerator, Enumerator::Lazy doesn't have enough information, so it needs to have some information only for inspect.<br>
Is it so important to make inspect rich?</p>
</blockquote>
<p>I'm not sure, but it would certainly be helpful when debugging.<br>
On the other hand, if that would impact significantly performance or code (maintainability), it's probably not worth it.</p>
<p>I guess I'm not used to a core Ruby class without a nice #inspect.</p>
</blockquote>
<p>I guess it wouldn't impact performance or maintainability so much, and fixed Enumerable::Lazy#inspect so that the following code:</p>
<p>(1..10).lazy.select(&:odd?).map(&:to_s).inspect</p>
<p>to return the following string:</p>
<p>"#<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: 1..10>:select>:map>"</p> Ruby master - Bug #6159: Enumerable::Lazy#inspecthttps://bugs.ruby-lang.org/issues/6159?journal_id=250842012-03-25T01:24:07ZEregon (Benoit Daloze)
<ul></ul><p>Awesome, thanks!</p>
<p>Your answer raises another question: Would it not be more readable if #inspect was closer to the code?</p>
<pre><code>(1..10).lazy.select(&:odd?).map(&:to_s).cycle(2).inspect
</code></pre>
<p>Instead of<br>
"#<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: 1..10>:select>:map>:cycle(2)>"<br>
Something like<br>
"#<Enumerator::Lazy: 1..10.select.map.cycle(2)>"<br>
?</p> Ruby master - Bug #6159: Enumerable::Lazy#inspecthttps://bugs.ruby-lang.org/issues/6159?journal_id=250852012-03-25T02:07:54Zshugo (Shugo Maeda)
<ul></ul><p>Eregon (Benoit Daloze) wrote:</p>
<blockquote>
<p>Your answer raises another question: Would it not be more readable if #inspect was closer to the code?</p>
<pre><code>(1..10).lazy.select(&:odd?).map(&:to_s).cycle(2).inspect
</code></pre>
<p>Instead of<br>
"#<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: 1..10>:select>:map>:cycle(2)>"<br>
Something like<br>
"#<Enumerator::Lazy: 1..10.select.map.cycle(2)>"<br>
?</p>
</blockquote>
<p>The former can distinguish the following lazy enumerators, but the latter can't:</p>
<p>p (1..10).lazy.select(&:odd).map(&:to_s)<br>
#=> #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: 1..10>:select>:map><br>
p (1..10).select.lazy.map(&:to_s)<br>
#=> #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1..10:select>>:map><br>
p (1..10).select.map.lazy<br>
#=> #<Enumerator::Lazy: #<Enumerator: #<Enumerator: 1..10:select>:map>></p>
<p>So I prefer the current behavior.</p> Ruby master - Bug #6159: Enumerable::Lazy#inspecthttps://bugs.ruby-lang.org/issues/6159?journal_id=250862012-03-25T05:05:54ZEregon (Benoit Daloze)
<ul></ul><p>Right, thank you for the explanation.</p> Ruby master - Bug #6159: Enumerable::Lazy#inspecthttps://bugs.ruby-lang.org/issues/6159?journal_id=251842012-03-27T00:29:20Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>Hello,</p>
<p>2012/3/25, shugo (Shugo Maeda) <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a>:</p>
<blockquote>
<p>So I prefer the current behavior.</p>
</blockquote>
<p>I agree with you, as a core team member.<br>
It is a simple and straightforward implementation.<br>
But I also agree with Benoit, as a user.<br>
The output is actually a bit verbose.</p>
<p>I guess the fault is the prefix "#<Enumerator::Lazy: ".<br>
It is too long and unfriendly for human eyes.</p>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a></p> Ruby master - Bug #6159: Enumerable::Lazy#inspecthttps://bugs.ruby-lang.org/issues/6159?journal_id=251922012-03-27T01:29:13Zshugo (Shugo Maeda)
<ul></ul><p>Hello,</p>
<p>2012/3/27 Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a>:</p>
<blockquote>
<blockquote>
<p>So I prefer the current behavior.</p>
</blockquote>
<p>I agree with you, as a core team member.<br>
It is a simple and straightforward implementation.<br>
But I also agree with Benoit, as a user.<br>
The output is actually a bit verbose.</p>
<p>I guess the fault is the prefix "#<Enumerator::Lazy: ".<br>
It is too long and unfriendly for human eyes.</p>
</blockquote>
<p>Hmm...could you make a counter proposal? We may be able to choose a<br>
shorter prefix such as "#<lazy", in which case, however, the class<br>
name information would be lost.</p>
<p>--<br>
Shugo Maeda</p>