Feature #5893

named return,next...

Added by Ondrej Bilka over 2 years ago. Updated about 2 years ago.

[ruby-core:42113]
Status:Rejected
Priority:Normal
Assignee:-
Category:-
Target version:2.0.0

Description

Hello. As returning from various blocks is recurring theme at list I propose following.

You can assign label to each block. You can exit given block by referring to its label.
Syntax can be ::label to avoid ambiguity(But prettier syntax would be desirable).

return,next,break,redo would work as they do now.

Here is example

while::loop true
10.times{|i|::outer
10.times{|j|::inter
next::outer if i>6
return::inner 42 if j>4
puts i,j
}
}::outer #For readability we could optionaly add label at end of block.
break::loop
end

History

#1 Updated by Anurag Priyam over 2 years ago

On Fri, Jan 13, 2012 at 7:21 PM, Ondrej Bilka neleai@seznam.cz wrote:

Hello. As returning from various blocks is recurring theme at list I propose following.

You can assign label to each block. You can exit given block by referring to its label.
Syntax can be ::label to avoid ambiguity(But prettier syntax would be desirable).

Doesn't throw/catch to that already?

--
Anurag Priyam

#2 Updated by Ondrej Bilka over 2 years ago

On Fri, Jan 13, 2012 at 11:11:28PM +0900, Anurag Priyam wrote:

On Fri, Jan 13, 2012 at 7:21 PM, Ondrej Bilka neleai@seznam.cz wrote:

Hello. As returning from various blocks is recurring theme at list I propose following.

You can assign label to each block. You can exit given block by referring to its label.
Syntax can be ::label to avoid ambiguity(But prettier syntax would be desirable).

Doesn't throw/catch to that already?
No unless you are happy with passing result by global variable.

#3 Updated by Ondrej Bilka over 2 years ago

On Fri, Jan 13, 2012 at 11:34:17PM +0900, Yukihiro Matsumoto wrote:

Hi,

In message "Re: Re: [ruby-trunk - Feature #5893][Open] named return,next..."
on Fri, 13 Jan 2012 23:26:36 +0900, Ondřej Bílka neleai@seznam.cz writes:

|> Doesn't throw/catch to that already?
|No unless you are happy with passing result by global variable.

Have you ever tried? throw can pass the result to catch.

                     matz.

I did not know this one. In code I have seen it is typically
something like this.

def returnit(foo)
$foo=foo
throw(:my
constant)
end

$foo=nil
t=try(:my_constant){
yield
}
t=$foo if $foo

#4 Updated by Anurag Priyam over 2 years ago

2012/1/13 Ondřej Bílka neleai@seznam.cz:

Yukihiro Matsumoto wrote:

 throw can pass the result to catch.

I did not know this one.

In my opinion, Sinatra is a very good example here. Look for
throw/catch in lib/sinatra/base.rb.

--
Anurag Priyam

#5 Updated by Yukihiro Matsumoto about 2 years ago

Hi,

In message "Re: Re: [ruby-trunk - Feature #5893][Open] named return,next..."
on Fri, 13 Jan 2012 23:26:36 +0900, Ondřej Bílka neleai@seznam.cz writes:

|> Doesn't throw/catch to that already?
|No unless you are happy with passing result by global variable.

Have you ever tried? throw can pass the result to catch.

                        matz.

#6 Updated by Yusuke Endoh about 2 years ago

  • Status changed from Open to Rejected

I believe this is already solved. Closing.

Yusuke Endoh mame@tsg.ne.jp

Also available in: Atom PDF