[#1611] set_trace_func/Array#fetch error — "Nathaniel Talbott" <nathaniel@...>

I've reduced the error I reported in ruby-talk:84013 to the following code:

17 messages 2003/10/11

Re: Yielding to a block from a proc?

From: Joel VanderWerf <vjoel@...>
Date: 2003-10-07 17:43:01 UTC
List: ruby-core #1590
Austin Ziegler wrote:
> On irc://irc.freenode.net/#ruby-lang tonight we were discussing procs. Among
> the discussion (which included unease about the differing semantics of proc 
> {}
> and Proc.new {}), the question came up about passing a block to a proc.
> Apparently, all of the following cause compile/syntax errors:
> 
>   proc { |a, &b| }
>   Proc.new { |a, &b| }
>   proc { yield }[] { "block given" }
>   Proc.new { yield }[] { "block given" }
> 
> More disturbing are the semantics of Proc#call:
> 
>   proc { yield }.call { "block given" }
>   Proc.new { yield }.call { "block given" }
> 
> These both result in a LocalJumpError. So it's not legal to use Proc#[], but
> Proc#call considers this legal with an impossible-to-fix error.
> 
> A parameter MAY be a proc and there's no problem with that.
> 
> Is this right? Is this pathological? Is it a bug? Is there a reason that 
> this
> isn't possible, other than the fact that it's pathological to want to do so?

I don't think it's pathological to want to do this:

   class << self
     instance_eval {
       define_method(:foo) { |a, &b| b[a] }
     }
   end

   #The above should have the same effect as:
   #def self.foo(a, &b); b[a]; end

   p(foo(3) {|x| x+1})


In This Thread

Prev Next