Forum: Ruby-dev [ruby-trunk - Feature #7877][Assigned] E::Lazy#with_index needed

Posted by shyouhei (Shyouhei Urabe) (Guest)
on 2013-02-18 12:28
(Received via mailing list)
Issue #7877 has been reported by shyouhei (Shyouhei Urabe).

----------------------------------------
Feature #7877: E::Lazy#with_index needed
https://bugs.ruby-lang.org/issues/7877

Author: shyouhei (Shyouhei Urabe)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: next minor


なんかLazyの有効な例を出そうと思ってそうだライプニッツ級数だ!ということで

def leibniz(n)
  (0..Float::INFINITY).lazy.with_index {|i, j| (-1 ** j) / (2*i+1).to_f 
}.take(n).reduce(:+)
end

とかやっても動かない(いや動くけど。止まらん)。残念です。これあったほうが便利じゃないですかね。どうでしょう。

あ、もちろん2.0.0以降でOKです。
Posted by Nobuyoshi Nakada (nobu)
on 2013-02-19 07:26
(Received via mailing list)
Issue #7877 has been updated by nobu (Nobuyoshi Nakada).

File 0001-enumerator.c-Enumerator-Lazy-with_index.patch added
Description updated


----------------------------------------
Feature #7877: E::Lazy#with_index needed
https://bugs.ruby-lang.org/issues/7877#change-36599

Author: shyouhei (Shyouhei Urabe)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: next minor


=begin
なんかLazyの有効な例を出そうと思ってそうだライプニッツ級数だ!ということで

  def leibniz(n)
    (0..Float::INFINITY).lazy.with_index {|i, j| (-1 ** j) / 
(2*i+1).to_f }.take(n).reduce(:+)
  end

とかやっても動かない(いや動くけど。止まらん)。残念です。これあったほうが便利じゃないですかね。どうでしょう。

あ、もちろん2.0.0以降でOKです。
=end
Posted by marcandre (Marc-Andre Lafortune) (Guest)
on 2013-02-19 08:18
(Received via mailing list)
Issue #7877 has been updated by marcandre (Marc-Andre Lafortune).


See #7696 on how to handle state...
----------------------------------------
Feature #7877: E::Lazy#with_index needed
https://bugs.ruby-lang.org/issues/7877#change-36600

Author: shyouhei (Shyouhei Urabe)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: next minor


=begin
なんかLazyの有効な例を出そうと思ってそうだライプニッツ級数だ!ということで

  def leibniz(n)
    (0..Float::INFINITY).lazy.with_index {|i, j| (-1 ** j) / 
(2*i+1).to_f }.take(n).reduce(:+)
  end

とかやっても動かない(いや動くけど。止まらん)。残念です。これあったほうが便利じゃないですかね。どうでしょう。

あ、もちろん2.0.0以降でOKです。
=end
Posted by shyouhei (Shyouhei Urabe) (Guest)
on 2013-02-19 12:43
(Received via mailing list)
Issue #7877 has been updated by shyouhei (Shyouhei Urabe).

Description updated

OK, so @marcandre is interested in.  I re-wrote the description in 
English.
----------------------------------------
Feature #7877: E::Lazy#with_index needed
https://bugs.ruby-lang.org/issues/7877#change-36605

Author: shyouhei (Shyouhei Urabe)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: next minor


=begin
So I wanted some real benefit of being lazy.  I wrote a Leibniz formula:

  def leibniz(n)
    (0..Float::INFINITY).lazy.with_index {|i, j| (-1 ** j) / 
(2*i+1).to_f }.take(n).reduce(:+)
  end

But it doesn't work (well, it does, indeed. It just doesn't stop 
working).  I got frustrated.
How about it?  Don't you feel it nifty?

Of course I can wait for the release next to 2.0.0.
=end
Posted by marcandre (Marc-Andre Lafortune) (Guest)
on 2013-02-19 17:30
(Received via mailing list)
Issue #7877 has been updated by marcandre (Marc-Andre Lafortune).


Note that (thanks to #7715), you can use `with_index` without a block 
and follow it with `map`:

    def leibniz(n)
      (0..Float::INFINITY).lazy.with_index.map {|i, j| (-1 ** j) / 
(2*i+1).to_f }.take(n).reduce(:+)
    end

I'm neutral about this feature request. The problem I see is that it's 
too late for 2.0.0 and it would introduce potential incompatibility in 
next minor.
----------------------------------------
Feature #7877: E::Lazy#with_index needed
https://bugs.ruby-lang.org/issues/7877#change-36623

Author: shyouhei (Shyouhei Urabe)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: next minor


=begin
So I wanted some real benefit of being lazy.  I wrote a Leibniz formula:

  def leibniz(n)
    (0..Float::INFINITY).lazy.with_index {|i, j| (-1 ** j) / 
(2*i+1).to_f }.take(n).reduce(:+)
  end

But it doesn't work (well, it does, indeed. It just doesn't stop 
working).  I got frustrated.
How about it?  Don't you feel it nifty?

Of course I can wait for the release next to 2.0.0.
=end
Posted by shyouhei (Shyouhei Urabe) (Guest)
on 2013-02-20 07:02
(Received via mailing list)
Issue #7877 has been updated by shyouhei (Shyouhei Urabe).


@marcandre oh, thank you!  You saved my day.

Still I want this though.


----------------------------------------
Feature #7877: E::Lazy#with_index needed
https://bugs.ruby-lang.org/issues/7877#change-36647

Author: shyouhei (Shyouhei Urabe)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: next minor


=begin
So I wanted some real benefit of being lazy.  I wrote a Leibniz formula:

  def leibniz(n)
    (0..Float::INFINITY).lazy.with_index {|i, j| (-1 ** j) / 
(2*i+1).to_f }.take(n).reduce(:+)
  end

But it doesn't work (well, it does, indeed. It just doesn't stop 
working).  I got frustrated.
How about it?  Don't you feel it nifty?

Of course I can wait for the release next to 2.0.0.
=end
Posted by zzak (Zachary Scott) (Guest)
on 2013-04-05 04:32
(Received via mailing list)
Issue #7877 has been updated by zzak (Zachary Scott).


Propose to move this to next major?
----------------------------------------
Feature #7877: E::Lazy#with_index needed
https://bugs.ruby-lang.org/issues/7877#change-38245

Author: shyouhei (Shyouhei Urabe)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: next minor


=begin
So I wanted some real benefit of being lazy.  I wrote a Leibniz formula:

  def leibniz(n)
    (0..Float::INFINITY).lazy.with_index {|i, j| (-1 ** j) / 
(2*i+1).to_f }.take(n).reduce(:+)
  end

But it doesn't work (well, it does, indeed. It just doesn't stop 
working).  I got frustrated.
How about it?  Don't you feel it nifty?

Of course I can wait for the release next to 2.0.0.
=end
Posted by "duerst (Martin Dürst)" <duerst@it.aoyama.ac.jp> (Guest)
on 2013-04-05 06:22
(Received via mailing list)
Issue #7877 has been updated by duerst (Martin Dürst).


zzak (Zachary Scott) wrote:
> Propose to move this to next major?

Do you mean because of "potential incompatibility" 
(https://bugs.ruby-lang.org/issues/7877#note-4)? What exactly would this 
incompatibility be? To me, it seems that lazy.with_index would just 
work, so we should just fix it. Next major seems way too long to wait.
----------------------------------------
Feature #7877: E::Lazy#with_index needed
https://bugs.ruby-lang.org/issues/7877#change-38252

Author: shyouhei (Shyouhei Urabe)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: next minor


=begin
So I wanted some real benefit of being lazy.  I wrote a Leibniz formula:

  def leibniz(n)
    (0..Float::INFINITY).lazy.with_index {|i, j| (-1 ** j) / 
(2*i+1).to_f }.take(n).reduce(:+)
  end

But it doesn't work (well, it does, indeed. It just doesn't stop 
working).  I got frustrated.
How about it?  Don't you feel it nifty?

Of course I can wait for the release next to 2.0.0.
=end
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.