Project

General

Profile

Actions

Bug #5746

closed

Proc#curry too strict about lambda's arity.

Added by marcandre (Marc-Andre Lafortune) about 13 years ago. Updated almost 12 years ago.

Status:
Closed
Target version:
-
ruby -v:
-
Backport:
[ruby-core:41594]

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 1 (0 open1 closed)

Blocked by Ruby master - Bug #5694: Proc#arity doesn't take optional arguments into account. Closednobu (Nobuyoshi Nakada)12/01/2011Actions

Updated by matz (Yukihiro Matsumoto) about 13 years ago

Hi,

In message "Re: [ruby-core:41594] [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 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.

Updated by Anonymous about 13 years ago

Hi,

On Sun, Dec 11, 2011 at 4:06 PM, Yukihiro Matsumoto wrote:

Hi,

In message "Re: [ruby-core:41594] [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 writes:

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

Actions #3

Updated by ko1 (Koichi Sasada) almost 13 years ago

  • Assignee set to mame (Yusuke Endoh)
Actions #4

Updated by shyouhei (Shyouhei Urabe) almost 13 years ago

  • Status changed from Open to Assigned
Actions #5

Updated by mame (Yusuke Endoh) over 12 years ago

  • Assignee changed from mame (Yusuke Endoh) to matz (Yukihiro Matsumoto)

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

--
Yusuke Endoh

Updated by ko1 (Koichi Sasada) over 12 years ago

  • Assignee changed from matz (Yukihiro Matsumoto) to nobu (Nobuyoshi Nakada)

Updated by marcandre (Marc-Andre Lafortune) over 12 years ago

  • Assignee changed from nobu (Nobuyoshi Nakada) to marcandre (Marc-Andre Lafortune)

Updated by marcandre (Marc-Andre Lafortune) almost 12 years ago

  • Status changed from Assigned to Closed

This was fixed when #5694 was resolved.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0