Feature #7314

Convert Proc to Lambda doesn't work in MRI

Added by Richard Schneeman over 1 year ago. Updated over 1 year ago.

[ruby-core:49112]
Status:Assigned
Priority:Normal
Assignee:Yukihiro Matsumoto
Category:-
Target version:next minor

Description

=begin

I have code where I need to convert a proc to a lambda (i need to be able to return out of the block). I would expect that passing a proc into a lambda to return a lambda. When I run this code on MRI i do not get the result I would expect

myproc = proc { |x| x }
my
lambda = lambda &myproc
my
lambda.lambda?

The result is (({false})) but I would expect it to be (({true}))

There is currently a way to turn a proc into a lambda in MRI like this:

def converttolambda &block
obj = Object.new
obj.definesingletonmethod(:, &block)
return obj.method(:
).to_proc
end

But this feels like a hack, and is not supported across other implementations. I would expect that passing a proc into a lambda to return a lambda, I believe it is a bug.

=end

History

#1 Updated by Shyouhei Urabe over 1 year ago

  • Tracker changed from Bug to Feature

Moved this to feature tracker. I think you are feeling this like a hack because, you are in fact doing something hacky (return from a block).

Anyway I'm not against that kind of feature, though I'm not sure if that can be achieved by lambda(&proc). So I feel a needs of discussion.

#2 Updated by Richard Schneeman over 1 year ago

=begin
I would like a standard way to turn a Proc into a lambda even if it cannot be achieved through (({lambda(&proc)})). I don't know if it will affect the outcome, but jRuby correctly returns a lambda from (({lambda(&proc)})) in 1.9 mode.
=end

#3 Updated by Yusuke Endoh over 1 year ago

  • Status changed from Open to Assigned
  • Assignee set to Yukihiro Matsumoto
  • Target version set to next minor

Matz will require a use case, I guess.

Yusuke Endoh mame@tsg.ne.jp

Also available in: Atom PDF