Project

General

Profile

Actions

Feature #5893

closed

named return,next...

Added by neleai (Ondrej Bilka) almost 13 years ago. Updated over 12 years ago.

Status:
Rejected
Assignee:
-
Target version:
[ruby-core:42113]

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

Updated by yeban (Anurag Priyam) almost 13 years ago

On Fri, Jan 13, 2012 at 7:21 PM, Ondrej Bilka 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

Updated by neleai (Ondrej Bilka) almost 13 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 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.

Updated by neleai (Ondrej Bilka) almost 13 years ago

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

Hi,

In message "Re: [ruby-core:42115] Re: [ruby-trunk - Feature #5893][Open] named return,next..."
on Fri, 13 Jan 2012 23:26:36 +0900, Ondřej Bílka 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 return_it(foo)
$foo=foo
throw(:my_constant)
end

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

Updated by yeban (Anurag Priyam) almost 13 years ago

2012/1/13 Ondřej Bílka :

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

Updated by matz (Yukihiro Matsumoto) over 12 years ago

Hi,

In message "Re: [ruby-core:42115] Re: [ruby-trunk - Feature #5893][Open] named return,next..."
on Fri, 13 Jan 2012 23:26:36 +0900, Ondřej Bílka 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.

Updated by mame (Yusuke Endoh) over 12 years ago

  • Status changed from Open to Rejected

I believe this is already solved. Closing.

--
Yusuke Endoh

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0