Bug #5746

Proc#curry too strict about lambda's arity.

Added by Marc-Andre Lafortune over 2 years ago. Updated about 1 year ago.

[ruby-core:41594]
Status:Closed
Priority:Normal
Assignee:Marc-Andre Lafortune
Category:core
Target version:-
ruby -v:- Backport:

Description

Currently, Proc#curry raises an error when you attempt to curry a lambda with optional (but limited) arguments:

l = ->(arg = 42) {}
l.curry(1) # => ArgumentError: wrong number of arguments (1 for 0)

Note that Proc#curry behaves correctly if the Proc was created from a method, even though arguments are treated the same way:

def Object.foo(arg = 42); end
m = Object.method(:foo).to_proc
m.class # => Proc, same as 'l'
m.lambda? # => true, same as 'l'
m.curry(1) # => curried proc

Referring to my evaluation method, my proposed fix passes SST:
a) usefulness: way more useful, as it makes it possible to do something that is not currently possible
b) consistency: makes it consistent with equivalent method
c) intuitiveness and d) performance: similar

It is straightforward (but not obvious), as it passes NIT (but not ODT).

This bug is a consequence of the redmine issue 5694; this will be fixed automatically when 5694 is fixed.


Related issues

Blocked by ruby-trunk - Bug #5694: Proc#arity doesn't take optional arguments into account. Closed 12/01/2011

History

#1 Updated by Yukihiro Matsumoto over 2 years ago

Hi,

In message "Re: [ruby-trunk - Bug #5746][Open] Proc#curry too strict about lambda's arity."
on Mon, 12 Dec 2011 02:08:08 +0900, Marc-Andre Lafortune ruby-core@marc-andre.ca writes:

|Currently, Proc#curry raises an error when you attempt to curry a lambda with optional (but limited) arguments:
|
| l = ->(arg = 42) {}
| l.curry(1) # => ArgumentError: wrong number of arguments (1 for 0)

In my opinion, #curry should not rely on #arity at all. Even after
proposed fix, it accepts l.curry(3) which is wrong. It should use
more reliable information such as #parameters.

                        matz.

#2 Updated by Anonymous over 2 years ago

Hi,

On Sun, Dec 11, 2011 at 4:06 PM, Yukihiro Matsumoto matz@ruby-lang.org wrote:

Hi,

In message "Re: [ruby-trunk - Bug #5746][Open] Proc#curry too strict about lambda's arity."
   on Mon, 12 Dec 2011 02:08:08 +0900, Marc-Andre Lafortune ruby-core@marc-andre.ca writes:

|Currently, Proc#curry raises an error when you attempt to curry a lambda with optional (but limited) arguments:
|
|    l

#3 Updated by Koichi Sasada about 2 years ago

  • Assignee set to Yusuke Endoh

#4 Updated by Shyouhei Urabe about 2 years ago

  • Status changed from Open to Assigned

#5 Updated by Yusuke Endoh almost 2 years ago

  • Assignee changed from Yusuke Endoh to Yukihiro Matsumoto

This issue is blocked by #5694 which is assigned to matz.
So I'm assigning this to matz.

Yusuke Endoh mame@tsg.ne.jp

#6 Updated by Koichi Sasada almost 2 years ago

  • Assignee changed from Yukihiro Matsumoto to Nobuyoshi Nakada

#7 Updated by Marc-Andre Lafortune almost 2 years ago

  • Assignee changed from Nobuyoshi Nakada to Marc-Andre Lafortune

#8 Updated by Marc-Andre Lafortune about 1 year ago

  • Status changed from Assigned to Closed

This was fixed when #5694 was resolved.

Also available in: Atom PDF