Issue Type: Bug Bug
Affects Versions: JRuby 1.7.0.pre1
Assignee: Thomas E Enebo
Components: Ruby 1.9.3
Created: 10/Jul/12 1:39 AM
Description:

Trying to use a curried proc and/or lambda with a Array.map() function does not work as expected.

It does work on MRI Ruby 1.9.3.

To replicate, see the following examples:

Jruby Version
>> array = [1, 2, 3, 4, 5]
=> [1, 2, 3, 4, 5]
>> add = lambda { |a, b| a + b }
=> #<Proc:0x44981fe9@(irb):2 (lambda)>
>> add.(2, 3)
=> 5
>> currying = add.curry
=> #<Proc:0x1d29109e@file:/opt/jruby/jruby-1.7.0.preview1/lib/jruby.jar!/jruby/kernel19/proc.rb:22 (lambda)>
>> _one_ = currying[1]
=> #<Proc:0x1d29109e@file:/opt/jruby/jruby-1.7.0.preview1/lib/jruby.jar!/jruby/kernel19/proc.rb:22 (lambda)>
>> one.(4)
=> 5
>> array.map(&one)
ArgumentError: wrong number of arguments (3 for 2)
        from org/jruby/RubyProc.java:254:in `call'
        from file:/opt/jruby/jruby-1.7.0.preview1/lib/jruby.jar!/jruby/kernel19/proc.rb:25:in `curry'
        from org/jruby/RubyArray.java:2350:in `map'
        from (irb):7:in `evaluate'
        from org/jruby/RubyKernel.java:1037:in `eval'
        from org/jruby/RubyKernel.java:1353:in `loop'
        from org/jruby/RubyKernel.java:1146:in `catch'
        from org/jruby/RubyKernel.java:1146:in `catch'
        from /opt/jruby/jruby-1.7.0.preview1/bin/jirb:13:in `(root)'
        from org/jruby/RubyKernel.java:1017:in `load'
        from -e:1:in `(root)'

Ruby MRI 1.9.3 (Works correctly)
irb(main):002:0> array = [1, 2, 3, 4, 5]
=> [1, 2, 3, 4, 5]
irb(main):003:0> add = lambda { |a, b| a + b }
=> #<Proc:0x0000000210d9c8@(irb):3 (lambda)>
irb(main):004:0> add.(2, 3)
=> 5
irb(main):005:0> currying = add.curry
=> #<Proc:0x000000020df460 (lambda)>
irb(main):006:0> _one_ = currying[1]
=> #<Proc:0x000000020c3a30 (lambda)>
irb(main):007:0> one.(4)
=> 5
irb(main):008:0> array.map(&one)
=> [2, 3, 4, 5, 6]

Doing the same thing with a Proc doesn't fail, but produces some strange results:

Jruby Version
>> array = [1, 2, 3, 4, 5]
=> [1, 2, 3, 4, 5]
>> add = Proc.new {|a,b| a + b}
=> #<Proc:0x5f571d2d@(irb):2>
>> add.(1, 2)
=> 3
>> currying = add.curry
=> #<Proc:0x95660e7@file:/opt/jruby/jruby-1.7.0.preview1/lib/jruby.jar!/jruby/kernel19/proc.rb:22>
>> _one_ = currying[1]
=> #<Proc:0x95660e7@file:/opt/jruby/jruby-1.7.0.preview1/lib/jruby.jar!/jruby/kernel19/proc.rb:22>
>> one.(4)
=> 5
>> array.map(&one)
=> [5, 5, 5, 5, 5]
Ruby MRI 1.9.3 (Works correctly)
irb(main):001:0> array = [1, 2, 3, 4, 5]
=> [1, 2, 3, 4, 5]
irb(main):002:0> add = Proc.new {|a,b| a + b}
=> #<Proc:0x0000000227b3f0@(irb):2>
irb(main):003:0> add.(1, 2)
=> 3
irb(main):004:0> currying = add.curry
=> #<Proc:0x0000000225e548>
irb(main):005:0> _one_ = currying[1]
=> #<Proc:0x00000002241470>
irb(main):006:0> one.(4)
=> 5
irb(main):007:0> array.map(&one)
=> [2, 3, 4, 5, 6]
Project: JRuby
Labels: lambda proc
Priority: Critical Critical
Reporter: Mark Mandel
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira
--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

Reply via email to