[#2529] concerns about Proc,lambda,block — "David A. Black" <dblack@...>

Hi --

39 messages 2004/03/01
[#2531] Re: concerns about Proc,lambda,block — ts <decoux@...> 2004/03/01

>>>>> "D" == David A Black <dblack@wobblini.net> writes:

[#2533] Re: concerns about Proc,lambda,block — "David A. Black" <dblack@...> 2004/03/01

Hi --

[#2537] Re: concerns about Proc,lambda,block — matz@... (Yukihiro Matsumoto) 2004/03/01

Hi,

[#2542] Re: concerns about Proc,lambda,block — Mathieu Bouchard <matju@...> 2004/03/02

[#2545] Re: concerns about Proc,lambda,block — matz@... (Yukihiro Matsumoto) 2004/03/02

Hi,

[#2550] Re: concerns about Proc,lambda,block — Mauricio Fern疣dez <batsman.geo@...> 2004/03/03

On Wed, Mar 03, 2004 at 07:51:10AM +0900, Yukihiro Matsumoto wrote:

[#2703] Proposed patch to add SSL support to net/pop.rb — Daniel Hobe <daniel@...>

This patch adds support to Net::POP for doing POP over SSL. Modeled on how

19 messages 2004/03/27
[#2704] Re: Proposed patch to add SSL support to net/pop.rb — Daniel Hobe <daniel@...> 2004/03/27

This is v2 of the patch. Cleaned up a bit and added some more docs.

[#2707] Re: Proposed patch to add SSL support to net/pop.rb — Daniel Hobe <daniel@...> 2004/03/28

v3 of the patch:

[#2721] Re: Proposed patch to add SSL support to net/pop.rb — Minero Aoki <aamine@...> 2004/03/30

Hi,

Re: questions... about Proc,lambda,block

From: matz@... (Yukihiro Matsumoto)
Date: 2004-03-05 03:43:34 UTC
List: ruby-core #2583
Hi,

I've noticed I haven't explained well about the Proc orphan.

"break" and "return" will cause LocalJumpError, when they are called
after their corresponding destination is passed.  For "break", the
destination is the block attached method invocation; for "return", it
is the method surrounding the block attached invocation.

Examples (some of them do not work right now as I explain in 1.8/1.9; I'm fixing them):

  Proc.new {
    break
  }.call        # LocalJumpError

# in above example, break is executed from "call", which is invoked
# after Proc.new is finished.

  def meth1(&block)
    block.call
  end
  meth1{break}  # fine

# this one is OK, because "call" is called before meth1 is finished.

  def meth2
    Proc.new{
      return
    }.call
  end           # fine

# this is OK, because at the point of "call", the destination (end of
# meth2) still exists.

  def meth3(&block)
    block
  end
  b=meth3{break}
  b.call        # LocalJumpError


# break is executed after meth3 finished.

  def meth4
    b = meth3{return}
    b.call
  end           # fine

# this is OK.  why?  because meth4 is still working.

  def meth5
    meth3{return}
  end 
  meth5.call    # LocalJumpError

# return from meth5 cannot be done after meth5 is finished.

  lambda{break}  # fine, no break will pass lambda
  lambda{return} # fine, no return will pass lambda

I should have organized things earlier, but I think (and I hope) this
is the final design decision about break and return from Procs, unless
someone prove me I'm wrong.

							matz.

In This Thread