ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require
@ 2011-06-06 14:11 Rodrigo Rosenfeld Rosas
  2011-06-06 14:18 ` [ruby-core:36786] " Michael Edgar
                   ` (27 more replies)
  0 siblings, 28 replies; 53+ messages in thread
From: Rodrigo Rosenfeld Rosas @ 2011-06-06 14:11 UTC (permalink / raw
  To: ruby-core


Issue #4840 has been reported by Rodrigo Rosenfeld Rosas.

----------------------------------------
Feature #4840: Allow returning from require
http://redmine.ruby-lang.org/issues/4840

Author: Rodrigo Rosenfeld Rosas
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


I have a situation where there is some code in Gitorious like:

unless defined? GitoriousConfig
  # tons of lines here
end

And I would it to look like

return if defined? GitoriousConfig

#tons of lines here

It would be great to allow return from a required file or some other keyword (break, etc or a new one)


-- 
http://redmine.ruby-lang.org

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:36786] Re: [Ruby 1.9 - Feature #4840][Open] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
@ 2011-06-06 14:18 ` Michael Edgar
  2011-06-06 15:00   ` [ruby-core:36793] " Magnus Holm
  2011-06-06 22:08   ` [ruby-core:36804] " Clifford Heath
  2011-06-07 10:10 ` [ruby-core:36811] " Yusuke ENDOH
                   ` (26 subsequent siblings)
  27 siblings, 2 replies; 53+ messages in thread
From: Michael Edgar @ 2011-06-06 14:18 UTC (permalink / raw
  To: ruby-core

On Jun 6, 2011, at 10:11 AM, Rodrigo Rosenfeld Rosas wrote:

> It would be great to allow return from a required file or some other keyword (break, etc or a new one)


This could be implemented as a method that raises an exception that `require` and `load` rescue.
I'm not sure how compatible that would be with custom require implementations (rubygems,
polyglot, etc), but it would obviate the need for a new keyword or commandeering an existing one.

Michael Edgar
adgar@carboni.ca
http://carboni.ca/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:36793] Re: [Ruby 1.9 - Feature #4840][Open] Allow returning from require
  2011-06-06 14:18 ` [ruby-core:36786] " Michael Edgar
@ 2011-06-06 15:00   ` Magnus Holm
  2011-06-06 22:08   ` [ruby-core:36804] " Clifford Heath
  1 sibling, 0 replies; 53+ messages in thread
From: Magnus Holm @ 2011-06-06 15:00 UTC (permalink / raw
  To: ruby-core

I think using "return" is quite natural in this case, as long as we
can use it in module/class-definitions too.

// Magnus Holm

On Mon, Jun 6, 2011 at 16:18, Michael Edgar <adgar@carboni.ca> wrote:
> On Jun 6, 2011, at 10:11 AM, Rodrigo Rosenfeld Rosas wrote:
>
>> It would be great to allow return from a required file or some other keyword (break, etc or a new one)
>
>
> This could be implemented as a method that raises an exception that `require` and `load` rescue.
> I'm not sure how compatible that would be with custom require implementations (rubygems,
> polyglot, etc), but it would obviate the need for a new keyword or commandeering an existing one.
>
> Michael Edgar
> adgar@carboni.ca
> http://carboni.ca/
>

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:36804] Re: [Ruby 1.9 - Feature #4840][Open] Allow returning from require
  2011-06-06 14:18 ` [ruby-core:36786] " Michael Edgar
  2011-06-06 15:00   ` [ruby-core:36793] " Magnus Holm
@ 2011-06-06 22:08   ` Clifford Heath
  2011-06-07  8:14     ` [ruby-core:36807] " Haase, Konstantin
  1 sibling, 1 reply; 53+ messages in thread
From: Clifford Heath @ 2011-06-06 22:08 UTC (permalink / raw
  To: ruby-core

On 07/06/2011, at 12:18 AM, Michael Edgar wrote:
> On Jun 6, 2011, at 10:11 AM, Rodrigo Rosenfeld Rosas wrote:
>> It would be great to allow return from a required file or some  
>> other keyword (break, etc or a new one)
>
> This could be implemented as a method that raises an exception that  
> `require` and `load` rescue.
> I'm not sure how compatible that would be with custom require  
> implementations (rubygems,
> polyglot, etc)

Polyglot will pass all exceptions except LoadError (or a subclass).
With a LoadError, if it has no further possibility to satisfy the  
require,
the original exception is re-raised. Thus, polyglot should not impede
the implementation you propose.

Clifford Heath.

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:36807] Re: [Ruby 1.9 - Feature #4840][Open] Allow returning from require
  2011-06-06 22:08   ` [ruby-core:36804] " Clifford Heath
@ 2011-06-07  8:14     ` Haase, Konstantin
  2011-06-07 11:19       ` [ruby-core:36816] " Rodrigo Rosenfeld Rosas
  0 siblings, 1 reply; 53+ messages in thread
From: Haase, Konstantin @ 2011-06-07  8:14 UTC (permalink / raw
  To: ruby-core@ruby-lang.org

How will that work with require? Remember it will only load the file once. Return false otherwise? (Which would be kinda compatible with the current behavior and using raise/throw). Or should those values be cached? If you want to use require CommonJS-style, it has to be cached. But what about return values that depend on or provoke side effects? Should files support early return?

Konstantin

On Jun 7, 2011, at 00:08 , Clifford Heath wrote:

> On 07/06/2011, at 12:18 AM, Michael Edgar wrote:
>> On Jun 6, 2011, at 10:11 AM, Rodrigo Rosenfeld Rosas wrote:
>>> It would be great to allow return from a required file or some  
>>> other keyword (break, etc or a new one)
>> 
>> This could be implemented as a method that raises an exception that  
>> `require` and `load` rescue.
>> I'm not sure how compatible that would be with custom require  
>> implementations (rubygems,
>> polyglot, etc)
> 
> Polyglot will pass all exceptions except LoadError (or a subclass).
> With a LoadError, if it has no further possibility to satisfy the  
> require,
> the original exception is re-raised. Thus, polyglot should not impede
> the implementation you propose.
> 
> Clifford Heath.
> 

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:36811] Re: [Ruby 1.9 - Feature #4840][Open] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
  2011-06-06 14:18 ` [ruby-core:36786] " Michael Edgar
@ 2011-06-07 10:10 ` Yusuke ENDOH
  2011-06-07 11:15   ` [ruby-core:36815] " Rodrigo Rosenfeld Rosas
  2011-06-08  0:33   ` [ruby-core:36830] " Yukihiro Matsumoto
  2012-03-25  7:10 ` [ruby-core:43632] [ruby-trunk - Feature #4840][Assigned] " mame (Yusuke Endoh)
                   ` (25 subsequent siblings)
  27 siblings, 2 replies; 53+ messages in thread
From: Yusuke ENDOH @ 2011-06-07 10:10 UTC (permalink / raw
  To: ruby-core

Hello,

2011/6/6 Rodrigo Rosenfeld Rosas <rr.rosas@gmail.com>:
> I have a situation where there is some code in Gitorious like:
>
> unless defined? GitoriousConfig
>  # tons of lines here
> end
>
> And I would it to look like
>
> return if defined? GitoriousConfig
>
> #tons of lines here
>
> It would be great to allow return from a required file or some other keyword (break, etc or a new one)


Agreed.  It would be also useful to write platform-specific code:

  require "test/unit"

  return unless /mswin|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM

  class TestForWindowsEnv < Test::Unit::TestCase
  ...


Here is an experimental patch:


diff --git a/compile.c b/compile.c
index 10d63bc..7b9c490 100644
--- a/compile.c
+++ b/compile.c
@@ -4291,10 +4291,6 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR
*ret, NODE * node, int poped)
 	rb_iseq_t *is = iseq;

 	if (is) {
-	    if (is->type == ISEQ_TYPE_TOP) {
-		COMPILE_ERROR((ERROR_ARGS "Invalid return"));
-	    }
-	    else {
 		LABEL *splabel = 0;

 		if (is->type == ISEQ_TYPE_METHOD) {
@@ -4321,7 +4317,6 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR
*ret, NODE * node, int poped)
 			ADD_INSN(ret, nd_line(node), pop);
 		    }
 		}
-	    }
 	}
 	break;
       }
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index f40dfdf..274f45d 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1561,8 +1561,6 @@ vm_throw(rb_thread_t *th, rb_control_frame_t *reg_cfp,
 		    cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
 		}

-		rb_vm_localjump_error("unexpected return", throwobj, TAG_RETURN);
-
 	      valid_return:
 		pt = dfp;
 	    }

-- 
Yusuke Endoh <mame@tsg.ne.jp>

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [ruby-core:36815] Re: [Ruby 1.9 - Feature #4840][Open] Allow returning from require
  2011-06-07 10:10 ` [ruby-core:36811] " Yusuke ENDOH
@ 2011-06-07 11:15   ` Rodrigo Rosenfeld Rosas
  2011-06-07 11:36     ` [ruby-core:36817] " Yusuke ENDOH
  2011-06-08  0:33   ` [ruby-core:36830] " Yukihiro Matsumoto
  1 sibling, 1 reply; 53+ messages in thread
From: Rodrigo Rosenfeld Rosas @ 2011-06-07 11:15 UTC (permalink / raw
  To: ruby-core

Em 07-06-2011 07:10, Yusuke ENDOH escreveu:
> Hello,
>
> 2011/6/6 Rodrigo Rosenfeld Rosas<rr.rosas@gmail.com>:
>> I have a situation where there is some code in Gitorious like:
>>
>> unless defined? GitoriousConfig
>>   # tons of lines here
>> end
>>
>> And I would it to look like
>>
>> return if defined? GitoriousConfig
>>
>> #tons of lines here
>>
>> It would be great to allow return from a required file or some other keyword (break, etc or a new one)
>
> Agreed.  It would be also useful to write platform-specific code:
>
>    require "test/unit"
>
>    return unless /mswin|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM
>
>    class TestForWindowsEnv<  Test::Unit::TestCase
>    ...
>
>
> Here is an experimental patch:
>
>
> diff --git a/compile.c b/compile.c
> index 10d63bc..7b9c490 100644
> --- a/compile.c
> +++ b/compile.c
> @@ -4291,10 +4291,6 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR
> *ret, NODE * node, int poped)
>   	rb_iseq_t *is = iseq;
>
>   	if (is) {
> -	    if (is->type == ISEQ_TYPE_TOP) {
> -		COMPILE_ERROR((ERROR_ARGS "Invalid return"));
> -	    }
> -	    else {
>   		LABEL *splabel = 0;
>
>   		if (is->type == ISEQ_TYPE_METHOD) {
> @@ -4321,7 +4317,6 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR
> *ret, NODE * node, int poped)
>   			ADD_INSN(ret, nd_line(node), pop);
>   		    }
>   		}
> -	    }
>   	}
>   	break;
>         }
> diff --git a/vm_insnhelper.c b/vm_insnhelper.c
> index f40dfdf..274f45d 100644
> --- a/vm_insnhelper.c
> +++ b/vm_insnhelper.c
> @@ -1561,8 +1561,6 @@ vm_throw(rb_thread_t *th, rb_control_frame_t *reg_cfp,
>   		    cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
>   		}
>
> -		rb_vm_localjump_error("unexpected return", throwobj, TAG_RETURN);
> -
>   	      valid_return:
>   		pt = dfp;
>   	    }
>

This patch is so small, that it seems strange that it affects only 
requires... Won't it have side effects? Notice that I didn't test it yet.

I agree with you about specific-platform tests use case too.

Thanks for your interest,

Rodrigo.

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:36816] Re: [Ruby 1.9 - Feature #4840][Open] Allow returning from require
  2011-06-07  8:14     ` [ruby-core:36807] " Haase, Konstantin
@ 2011-06-07 11:19       ` Rodrigo Rosenfeld Rosas
  0 siblings, 0 replies; 53+ messages in thread
From: Rodrigo Rosenfeld Rosas @ 2011-06-07 11:19 UTC (permalink / raw
  To: ruby-core

Em 07-06-2011 05:14, Haase, Konstantin escreveu:
> How will that work with require? Remember it will only load the file once. Return false otherwise? (Which would be kinda compatible with the current behavior and using raise/throw). Or should those values be cached? If you want to use require CommonJS-style, it has to be cached. But what about return values that depend on or provoke side effects? Should files support early return?

I was thinking about that yesterday, but I have no idea how this should 
work. If an aborted required should return true or false. Or a value 
defined by the return, like:

return :aborted if should_abort?

Or if require should accept some block as:

require('some/file'){|return_value| do_something_with return_value }

Really, I have no idea about this!

Best regards,

Rodrigo.

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:36817] Re: [Ruby 1.9 - Feature #4840][Open] Allow returning from require
  2011-06-07 11:15   ` [ruby-core:36815] " Rodrigo Rosenfeld Rosas
@ 2011-06-07 11:36     ` Yusuke ENDOH
  0 siblings, 0 replies; 53+ messages in thread
From: Yusuke ENDOH @ 2011-06-07 11:36 UTC (permalink / raw
  To: ruby-core

Hello,

2011/6/7 Rodrigo Rosenfeld Rosas <rr.rosas@gmail.com>:
> This patch is so small, that it seems strange that it affects only
> requires... Won't it have side effects? Notice that I didn't test it yet.

I'm not sure.
But surprisingly, the patch passes all tests except one.

-- 
Yusuke Endoh <mame@tsg.ne.jp>

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:36830] Re: [Ruby 1.9 - Feature #4840][Open] Allow returning from require
  2011-06-07 10:10 ` [ruby-core:36811] " Yusuke ENDOH
  2011-06-07 11:15   ` [ruby-core:36815] " Rodrigo Rosenfeld Rosas
@ 2011-06-08  0:33   ` Yukihiro Matsumoto
  2011-06-08  7:38     ` [ruby-core:36831] " Charles Oliver Nutter
                       ` (2 more replies)
  1 sibling, 3 replies; 53+ messages in thread
From: Yukihiro Matsumoto @ 2011-06-08  0:33 UTC (permalink / raw
  To: ruby-core

Hi,

In message "Re: [ruby-core:36811] Re: [Ruby 1.9 - Feature #4840][Open] Allow returning from require"
    on Tue, 7 Jun 2011 19:10:15 +0900, Yusuke ENDOH <mame@tsg.ne.jp> writes:

|Agreed.

Ah, I understand the request.  But returning from outside of a method
makes me so weird.

							matz.

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:36831] Re: [Ruby 1.9 - Feature #4840][Open] Allow returning from require
  2011-06-08  0:33   ` [ruby-core:36830] " Yukihiro Matsumoto
@ 2011-06-08  7:38     ` Charles Oliver Nutter
  2011-06-08  8:43       ` [ruby-core:36837] " Adam Prescott
  2011-06-08  9:22     ` [ruby-core:36839] " Ryan Davis
  2011-06-08 11:57     ` [ruby-core:36844] " Alex Young
  2 siblings, 1 reply; 53+ messages in thread
From: Charles Oliver Nutter @ 2011-06-08  7:38 UTC (permalink / raw
  To: ruby-core

On Tue, Jun 7, 2011 at 7:33 PM, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
> Ah, I understand the request.  But returning from outside of a method
> makes me so weird.

I agree with both the feature and the fact that return outside a
method feels weird. An early termination of a loading file would be
welcome; I've wanted this many times, and always ended up doing the
super-gross "giant if" to accomplish what could be done by a simple
early exit.

I wonder if a core method that does the early return would be a better
option, like Kernel#exit_script. It could be implemented to throw an
exception all requires and loads expect to catch, like
"ExitScriptError" or something. That would seem more consistent than
having return end the script...but not actually be returning anything.

Another option would be to use a different keyword that isn't so tied
to method/proc bodies, like "break"

break if defined? GitoriousConfig

I think I like the exit_script version better, though.

exit_script if defined? GitoriousConfig

- Charlie

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:36837] Re: [Ruby 1.9 - Feature #4840][Open] Allow returning from require
  2011-06-08  7:38     ` [ruby-core:36831] " Charles Oliver Nutter
@ 2011-06-08  8:43       ` Adam Prescott
  0 siblings, 0 replies; 53+ messages in thread
From: Adam Prescott @ 2011-06-08  8:43 UTC (permalink / raw
  To: ruby-core

[-- Attachment #1: Type: text/plain, Size: 302 bytes --]

On Wed, Jun 8, 2011 at 8:38 AM, Charles Oliver Nutter
<headius@headius.com>wrote:

> exit_script if defined? GitoriousConfig
>

This could be confusing, if you happen to view the entire program as a
script. You might think that "exit_script" will do the same thing as
"abort". I like the idea, though.

[-- Attachment #2: Type: text/html, Size: 583 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:36839] Re: [Ruby 1.9 - Feature #4840][Open] Allow returning from require
  2011-06-08  0:33   ` [ruby-core:36830] " Yukihiro Matsumoto
  2011-06-08  7:38     ` [ruby-core:36831] " Charles Oliver Nutter
@ 2011-06-08  9:22     ` Ryan Davis
  2011-06-08  9:24       ` [ruby-core:36840] " Charles Oliver Nutter
  2011-06-08 11:57     ` [ruby-core:36844] " Alex Young
  2 siblings, 1 reply; 53+ messages in thread
From: Ryan Davis @ 2011-06-08  9:22 UTC (permalink / raw
  To: ruby-core


On Jun 7, 2011, at 17:33 , Yukihiro Matsumoto wrote:

> Hi,
> 
> In message "Re: [ruby-core:36811] Re: [Ruby 1.9 - Feature #4840][Open] Allow returning from require"
>    on Tue, 7 Jun 2011 19:10:15 +0900, Yusuke ENDOH <mame@tsg.ne.jp> writes:
> 
> |Agreed.
> 
> Ah, I understand the request.  But returning from outside of a method
> makes me so weird.

How about raising a specific exception that is rescued by #require instead?

class AbortRequire < StandardError; end

alias :original_require :require

def require f
  original_require f
rescue AbortRequire
  false
end

def 

p require 'f' # => false

# f.rb:

raise AbortRequire if defined? GitoriousConfig

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:36840] Re: [Ruby 1.9 - Feature #4840][Open] Allow returning from require
  2011-06-08  9:22     ` [ruby-core:36839] " Ryan Davis
@ 2011-06-08  9:24       ` Charles Oliver Nutter
  0 siblings, 0 replies; 53+ messages in thread
From: Charles Oliver Nutter @ 2011-06-08  9:24 UTC (permalink / raw
  To: ruby-core

On Wed, Jun 8, 2011 at 4:22 AM, Ryan Davis <ryand-ruby@zenspider.com> wrote:
> How about raising a specific exception that is rescued by #require instead?
>
> class AbortRequire < StandardError; end
...
> raise AbortRequire if defined? GitoriousConfig

That's pretty clean too. Name needs work ;)

I almost suggested a special catch tag that all requires wrap, but
catch/throw is a little arcane for most folks...

- Charlie

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:36844] Re: [Ruby 1.9 - Feature #4840][Open] Allow returning from require
  2011-06-08  0:33   ` [ruby-core:36830] " Yukihiro Matsumoto
  2011-06-08  7:38     ` [ruby-core:36831] " Charles Oliver Nutter
  2011-06-08  9:22     ` [ruby-core:36839] " Ryan Davis
@ 2011-06-08 11:57     ` Alex Young
  2011-06-08 12:00       ` [ruby-core:36845] " Haase, Konstantin
  2 siblings, 1 reply; 53+ messages in thread
From: Alex Young @ 2011-06-08 11:57 UTC (permalink / raw
  To: ruby-core

On 08/06/11 01:33, Yukihiro Matsumoto wrote:
> Hi,
> 
> In message "Re: [ruby-core:36811] Re: [Ruby 1.9 - Feature #4840][Open] Allow returning from require"
>     on Tue, 7 Jun 2011 19:10:15 +0900, Yusuke ENDOH <mame@tsg.ne.jp> writes:
> 
> |Agreed.
> 
> Ah, I understand the request.  But returning from outside of a method
> makes me so weird.

To me, return would imply that the returned value should be passed back
by the original require call, like so:

$ cat a.rb
return 42

$ cat b.rb
p require("a")

$ ruby -I. b.rb
42


That could be *really* handy, although it's not compatible with my
previous suggestion (currently languishing here:
http://redmine.ruby-lang.org/issues/4523 - any comments?). An
already-loaded file can still be signaled by a nil return value, and a
file could pretend to be already loaded (if that's at all useful) by
choosing nil as its return value...

Food for thought :-)

-- 
Alex

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:36845] Re: [Ruby 1.9 - Feature #4840][Open] Allow returning from require
  2011-06-08 11:57     ` [ruby-core:36844] " Alex Young
@ 2011-06-08 12:00       ` Haase, Konstantin
  0 siblings, 0 replies; 53+ messages in thread
From: Haase, Konstantin @ 2011-06-08 12:00 UTC (permalink / raw
  To: ruby-core@ruby-lang.org

One real use case I see would be avoiding global state (like CommonJS). However, if an already required file return nil, this is not possible.
On Jun 8, 2011, at 13:57 , Alex Young wrote:

> On 08/06/11 01:33, Yukihiro Matsumoto wrote:
>> Hi,
>> 
>> In message "Re: [ruby-core:36811] Re: [Ruby 1.9 - Feature #4840][Open] Allow returning from require"
>>    on Tue, 7 Jun 2011 19:10:15 +0900, Yusuke ENDOH <mame@tsg.ne.jp> writes:
>> 
>> |Agreed.
>> 
>> Ah, I understand the request.  But returning from outside of a method
>> makes me so weird.
> 
> To me, return would imply that the returned value should be passed back
> by the original require call, like so:
> 
> $ cat a.rb
> return 42
> 
> $ cat b.rb
> p require("a")
> 
> $ ruby -I. b.rb
> 42
> 
> 
> That could be *really* handy, although it's not compatible with my
> previous suggestion (currently languishing here:
> http://redmine.ruby-lang.org/issues/4523 - any comments?). An
> already-loaded file can still be signaled by a nil return value, and a
> file could pretend to be already loaded (if that's at all useful) by
> choosing nil as its return value...
> 
> Food for thought :-)
> 
> -- 
> Alex
> 

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:43632] [ruby-trunk - Feature #4840][Assigned] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
  2011-06-06 14:18 ` [ruby-core:36786] " Michael Edgar
  2011-06-07 10:10 ` [ruby-core:36811] " Yusuke ENDOH
@ 2012-03-25  7:10 ` mame (Yusuke Endoh)
  2012-03-25 15:07 ` [ruby-core:43667] [ruby-trunk - Feature #4840] " trans (Thomas Sawyer)
                   ` (24 subsequent siblings)
  27 siblings, 0 replies; 53+ messages in thread
From: mame (Yusuke Endoh) @ 2012-03-25  7:10 UTC (permalink / raw
  To: ruby-core


Issue #4840 has been updated by mame (Yusuke Endoh).

Status changed from Open to Assigned
Assignee set to matz (Yukihiro Matsumoto)


----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-25132

Author: rosenfeld (Rodrigo Rosenfeld Rosas)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: 


I have a situation where there is some code in Gitorious like:

unless defined? GitoriousConfig
  # tons of lines here
end

And I would it to look like

return if defined? GitoriousConfig

#tons of lines here

It would be great to allow return from a required file or some other keyword (break, etc or a new one)


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:43667] [ruby-trunk - Feature #4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (2 preceding siblings ...)
  2012-03-25  7:10 ` [ruby-core:43632] [ruby-trunk - Feature #4840][Assigned] " mame (Yusuke Endoh)
@ 2012-03-25 15:07 ` trans (Thomas Sawyer)
  2012-06-07 17:38 ` [ruby-core:45482] " rosenfeld (Rodrigo Rosenfeld Rosas)
                   ` (23 subsequent siblings)
  27 siblings, 0 replies; 53+ messages in thread
From: trans (Thomas Sawyer) @ 2012-03-25 15:07 UTC (permalink / raw
  To: ruby-core


Issue #4840 has been updated by trans (Thomas Sawyer).


I've had occasion to use this as well, especially for RUBY_VERSION specific code.

I wonder if it is okay to be embedded in other code though. Would this work?

  class Q
    def foo
      exit_script
    end
  end

  Q.new.foo

Is it a good idea for it to work? Or should exit_script only be allowed at toplevel?

----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-25169

Author: rosenfeld (Rodrigo Rosenfeld Rosas)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: 


I have a situation where there is some code in Gitorious like:

unless defined? GitoriousConfig
  # tons of lines here
end

And I would it to look like

return if defined? GitoriousConfig

#tons of lines here

It would be great to allow return from a required file or some other keyword (break, etc or a new one)


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:45482] [ruby-trunk - Feature #4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (3 preceding siblings ...)
  2012-03-25 15:07 ` [ruby-core:43667] [ruby-trunk - Feature #4840] " trans (Thomas Sawyer)
@ 2012-06-07 17:38 ` rosenfeld (Rodrigo Rosenfeld Rosas)
  2012-06-07 23:00 ` [ruby-core:45493] " mame (Yusuke Endoh)
                   ` (22 subsequent siblings)
  27 siblings, 0 replies; 53+ messages in thread
From: rosenfeld (Rodrigo Rosenfeld Rosas) @ 2012-06-07 17:38 UTC (permalink / raw
  To: ruby-core


Issue #4840 has been updated by rosenfeld (Rodrigo Rosenfeld Rosas).

File feature-4840.odp added


----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-27072

Author: rosenfeld (Rodrigo Rosenfeld Rosas)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: 


I have a situation where there is some code in Gitorious like:

unless defined? GitoriousConfig
  # tons of lines here
end

And I would it to look like

return if defined? GitoriousConfig

#tons of lines here

It would be great to allow return from a required file or some other keyword (break, etc or a new one)


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:45493] [ruby-trunk - Feature #4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (4 preceding siblings ...)
  2012-06-07 17:38 ` [ruby-core:45482] " rosenfeld (Rodrigo Rosenfeld Rosas)
@ 2012-06-07 23:00 ` mame (Yusuke Endoh)
  2012-06-08 12:51 ` [ruby-core:45511] " rosenfeld (Rodrigo Rosenfeld Rosas)
                   ` (21 subsequent siblings)
  27 siblings, 0 replies; 53+ messages in thread
From: mame (Yusuke Endoh) @ 2012-06-07 23:00 UTC (permalink / raw
  To: ruby-core


Issue #4840 has been updated by mame (Yusuke Endoh).


Received.  Thanks for quick action!

But, matz said "returning from outside of a method makes me so weird" once.
I'm ok if you want to give it a second try with no change, but I guess matz is not likely to accept it for the same reason.
(Well, but, maybe it isn't so bad way because he sometimes changes his mind)

-- 
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-27081

Author: rosenfeld (Rodrigo Rosenfeld Rosas)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: 


I have a situation where there is some code in Gitorious like:

unless defined? GitoriousConfig
  # tons of lines here
end

And I would it to look like

return if defined? GitoriousConfig

#tons of lines here

It would be great to allow return from a required file or some other keyword (break, etc or a new one)


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:45511] [ruby-trunk - Feature #4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (5 preceding siblings ...)
  2012-06-07 23:00 ` [ruby-core:45493] " mame (Yusuke Endoh)
@ 2012-06-08 12:51 ` rosenfeld (Rodrigo Rosenfeld Rosas)
  2012-07-23 13:12 ` [ruby-core:46648] " mame (Yusuke Endoh)
                   ` (20 subsequent siblings)
  27 siblings, 0 replies; 53+ messages in thread
From: rosenfeld (Rodrigo Rosenfeld Rosas) @ 2012-06-08 12:51 UTC (permalink / raw
  To: ruby-core


Issue #4840 has been updated by rosenfeld (Rodrigo Rosenfeld Rosas).


thanks for worrying, but I'll take the risk :)
----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-27098

Author: rosenfeld (Rodrigo Rosenfeld Rosas)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: 


I have a situation where there is some code in Gitorious like:

unless defined? GitoriousConfig
  # tons of lines here
end

And I would it to look like

return if defined? GitoriousConfig

#tons of lines here

It would be great to allow return from a required file or some other keyword (break, etc or a new one)


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:46648] [ruby-trunk - Feature #4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (6 preceding siblings ...)
  2012-06-08 12:51 ` [ruby-core:45511] " rosenfeld (Rodrigo Rosenfeld Rosas)
@ 2012-07-23 13:12 ` mame (Yusuke Endoh)
  2012-07-23 14:57   ` [ruby-core:46667] " Rodrigo Rosenfeld Rosas
  2012-07-23 15:44 ` [ruby-core:46673] " alexeymuranov (Alexey Muranov)
                   ` (19 subsequent siblings)
  27 siblings, 1 reply; 53+ messages in thread
From: mame (Yusuke Endoh) @ 2012-07-23 13:12 UTC (permalink / raw
  To: ruby-core


Issue #4840 has been updated by mame (Yusuke Endoh).


Rodrigo Rosenfeld Rosas,

At the developer meeting (7/21), Matz was basically positive
to this proposal, but it turned out that we still need to
discuss corner cases.


Here is a discussion summary.

* Matz said that he will accept "return from toplevel", but
  that reject "return from class definition".

  return if cond # OK
  class Foo
    return if cond # NG
  end

* "return from toplevel" should always discard the argument.

* What's happen if it returns from the start script (the given
  script to interpreter as a cmdline)?

  - The argument should be discarded; it does NOT affect the
    process termination status code

  - The same as "exit", but cannot rescue SystemExit

* What's happen in the following corner cases?

  - eval("return") in toplevel

  - proc { return }.call in toplevel

* Matz prefered "return" to "a special exception that require
  and load rescue",

  - though some people (including ko1) prefered the latter.

-- 
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-28309

Author: rosenfeld (Rodrigo Rosenfeld Rosas)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: 


I have a situation where there is some code in Gitorious like:

unless defined? GitoriousConfig
  # tons of lines here
end

And I would it to look like

return if defined? GitoriousConfig

#tons of lines here

It would be great to allow return from a required file or some other keyword (break, etc or a new one)


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:46667] Re: [ruby-trunk - Feature #4840] Allow returning from require
  2012-07-23 13:12 ` [ruby-core:46648] " mame (Yusuke Endoh)
@ 2012-07-23 14:57   ` Rodrigo Rosenfeld Rosas
  2012-07-24  1:37     ` [ruby-core:46702] " SASADA Koichi
  0 siblings, 1 reply; 53+ messages in thread
From: Rodrigo Rosenfeld Rosas @ 2012-07-23 14:57 UTC (permalink / raw
  To: ruby-core

Em 23-07-2012 10:12, mame (Yusuke Endoh) escreveu:
> Issue #4840 has been updated by mame (Yusuke Endoh).
>
>
> Rodrigo Rosenfeld Rosas,
>
> At the developer meeting (7/21), Matz was basically positive
> to this proposal, but it turned out that we still need to
> discuss corner cases.
>
>
> Here is a discussion summary.
>
> * Matz said that he will accept "return from toplevel", but
>    that reject "return from class definition".
>
>    return if cond # OK
>    class Foo
>      return if cond # NG
>    end

Totally agree.

> * "return from toplevel" should always discard the argument.

You mean "return something", right? I agree. Maybe we could even issue 
an exception if anything other than just "return" is used.

> * What's happen if it returns from the start script (the given
>    script to interpreter as a cmdline)?
>
>    - The argument should be discarded; it does NOT affect the
>      process termination status code
>
>    - The same as "exit", but cannot rescue SystemExit

Agreed. Specifically "return" should be equivalent to "exit 0", right? 
And "return -1" (or any other value, including 0) shouldn't be allowed 
in my opinion, raising an exception, in which case the return value 
wouldn't be 0 obviously :)

> * What's happen in the following corner cases?
>
>    - eval("return") in toplevel

I'd vote for just abandoning any subsequent code in the eval and nothing 
else. Maybe for that case "return" could use the arguments for the 
result of "eval".

>    - proc { return }.call in toplevel

If it is the main program, "exit" would be the equivalent. Otherwise, no 
code would be interpreted after the "call" call.

I don't understand what makes this so special.

> * Matz prefered "return" to "a special exception that require
>    and load rescue",
>
>    - though some people (including ko1) prefered the latter.

I'm okay with raising an exception that would be rescued by require, 
require_relative and load.

Actually I guess this is the simpler approach and it fulfills all the 
real use cases I could think of in this moment.

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:46673] [ruby-trunk - Feature #4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (7 preceding siblings ...)
  2012-07-23 13:12 ` [ruby-core:46648] " mame (Yusuke Endoh)
@ 2012-07-23 15:44 ` alexeymuranov (Alexey Muranov)
  2012-07-24  1:26   ` [ruby-core:46701] " SASADA Koichi
  2012-07-24  7:52 ` [ruby-core:46714] " alexeymuranov (Alexey Muranov)
                   ` (18 subsequent siblings)
  27 siblings, 1 reply; 53+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2012-07-23 15:44 UTC (permalink / raw
  To: ruby-core


Issue #4840 has been updated by alexeymuranov (Alexey Muranov).


How about redefining `__END__` to allow to call it as a method?
----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-28338

Author: rosenfeld (Rodrigo Rosenfeld Rosas)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: 


I have a situation where there is some code in Gitorious like:

unless defined? GitoriousConfig
  # tons of lines here
end

And I would it to look like

return if defined? GitoriousConfig

#tons of lines here

It would be great to allow return from a required file or some other keyword (break, etc or a new one)


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:46701] Re: [ruby-trunk - Feature #4840] Allow returning from require
  2012-07-23 15:44 ` [ruby-core:46673] " alexeymuranov (Alexey Muranov)
@ 2012-07-24  1:26   ` SASADA Koichi
  2012-07-24  2:42     ` [ruby-core:46704] " Trans
  0 siblings, 1 reply; 53+ messages in thread
From: SASADA Koichi @ 2012-07-24  1:26 UTC (permalink / raw
  To: ruby-core

(2012/07/24 0:44), alexeymuranov (Alexey Muranov) wrote:
> 
> How about redefining `__END__` to allow to call it as a method?

It has compatibility issue that __END__ is related to DATA.

-- 
// SASADA Koichi at atdot dot net

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:46702] Re: [ruby-trunk - Feature #4840] Allow returning from require
  2012-07-23 14:57   ` [ruby-core:46667] " Rodrigo Rosenfeld Rosas
@ 2012-07-24  1:37     ` SASADA Koichi
  2012-07-24  2:47       ` [ruby-core:46705] " Rodrigo Rosenfeld Rosas
  0 siblings, 1 reply; 53+ messages in thread
From: SASADA Koichi @ 2012-07-24  1:37 UTC (permalink / raw
  To: ruby-core

(2012/07/23 23:57), Rodrigo Rosenfeld Rosas wrote:
>> * "return from toplevel" should always discard the argument.
> 
> You mean "return something", right? I agree. Maybe we could even issue
> an exception if anything other than just "return" is used.
> 
>> * What's happen if it returns from the start script (the given
>>    script to interpreter as a cmdline)?
>>
>>    - The argument should be discarded; it does NOT affect the
>>      process termination status code
>>
>>    - The same as "exit", but cannot rescue SystemExit
> 
> Agreed. Specifically "return" should be equivalent to "exit 0", right?
> And "return -1" (or any other value, including 0) shouldn't be allowed
> in my opinion, raising an exception, in which case the return value
> wouldn't be 0 obviously :)

matz proposed that ignore return argument completely.  matz also said to
avoid mistake, return expression with argument (example: "return foo")
should be syntax error.


>>    - proc { return }.call in toplevel
> 
> If it is the main program, "exit" would be the equivalent. Otherwise, no
> code would be interpreted after the "call" call.
> 
> I don't understand what makes this so special.

(1)
  pr = proc{return}
  def foo(pr)
    pr.call # what happen?
  end

(1')
  1.times{
    return
  }

(2)
  # a.rb
  $pr = proc{return}

  # b.rb
  require './a.rb'
  $pr.call # waht happen?

(3)
  begin
    ...
  rescue
    return
  ensure
    return
  end

matz proposed that "accept return on toplevel (not in block, classes, etc)".

>> * Matz prefered "return" to "a special exception that require
>>    and load rescue",
>>
>>    - though some people (including ko1) prefered the latter.
> 
> I'm okay with raising an exception that would be rescued by require,
> require_relative and load.
> 
> Actually I guess this is the simpler approach and it fulfills all the
> real use cases I could think of in this moment.

I strongly recommended the exception approach because there are *NO*
difficult corner cases.

However, matz disagreed the exception approach because of "raise
StopLoading is too long".  It is a kind of "name is not good".

-- 
// SASADA Koichi at atdot dot net

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:46704] Re: [ruby-trunk - Feature #4840] Allow returning from require
  2012-07-24  1:26   ` [ruby-core:46701] " SASADA Koichi
@ 2012-07-24  2:42     ` Trans
  2012-07-24  2:49       ` [ruby-core:46706] " Urabe Shyouhei
  2012-07-24 17:52       ` [ruby-core:46735] " Eric Hodel
  0 siblings, 2 replies; 53+ messages in thread
From: Trans @ 2012-07-24  2:42 UTC (permalink / raw
  To: ruby-core

>> How about redefining `__END__` to allow to call it as a method?
>
> It has compatibility issue that __END__ is related to DATA.

Then what about `__end__`?

Tangentially, why not deprecate __END__? Is there some really
important use case that we just can't live without? The whole idea
strikes me as rather hackish, especially considering it is limited to
main file.

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:46705] Re: [ruby-trunk - Feature #4840] Allow returning from require
  2012-07-24  1:37     ` [ruby-core:46702] " SASADA Koichi
@ 2012-07-24  2:47       ` Rodrigo Rosenfeld Rosas
  0 siblings, 0 replies; 53+ messages in thread
From: Rodrigo Rosenfeld Rosas @ 2012-07-24  2:47 UTC (permalink / raw
  To: ruby-core

Em 23-07-2012 22:37, SASADA Koichi escreveu:
> (2012/07/23 23:57), Rodrigo Rosenfeld Rosas wrote:
>>> * "return from toplevel" should always discard the argument.
>> You mean "return something", right? I agree. Maybe we could even issue
>> an exception if anything other than just "return" is used.
>>
>>> * What's happen if it returns from the start script (the given
>>>     script to interpreter as a cmdline)?
>>>
>>>     - The argument should be discarded; it does NOT affect the
>>>       process termination status code
>>>
>>>     - The same as "exit", but cannot rescue SystemExit
>> Agreed. Specifically "return" should be equivalent to "exit 0", right?
>> And "return -1" (or any other value, including 0) shouldn't be allowed
>> in my opinion, raising an exception, in which case the return value
>> wouldn't be 0 obviously :)
> matz proposed that ignore return argument completely.  matz also said to
> avoid mistake, return expression with argument (example: "return foo")
> should be syntax error.

Better yet.

>>>     - proc { return }.call in toplevel
>> If it is the main program, "exit" would be the equivalent. Otherwise, no
>> code would be interpreted after the "call" call.
>>
>> I don't understand what makes this so special.
> (1)
>    pr = proc{return}
>    def foo(pr)
>      pr.call # what happen?
>    end

I wonder why someone would write code like this in the first place, but 
if someone did he is probably expecting the program to terminate with 
exit if this is the main file. For required files I have no idea what 
someone would expect from code like this. I'd probably raise an 
exception in such situation because it is most likely a logic error that 
could be hard to debug... I know what you mean, should that method "foo" 
be defined or not? What should be its definition? I have no idea because 
code like this simply doesn't make any sense to me.

> (1')
>    1.times{
>      return
>    }

This one I can think of. But something like:

['a', 'b'].each {|item|
   return if defined? item2module(item)
}

This would simply return from the require. I still don't understand why 
this would be so special.

> (2)
>    # a.rb
>    $pr = proc{return}

Wow! I wouldn't ever think in something like this! Congratulations, 
you're really creative!

Again, why the hell would someone do something like this? I'd just raise 
an error when trying to call $pr because return has no more meaning 
after that file has been already required.

>    # b.rb
>    require './a.rb'
>    $pr.call # waht happen?
>
> (3)
>    begin
>      ...
>    rescue
>      return
>    ensure
>      return
>    end
>
> matz proposed that "accept return on toplevel (not in block, classes, etc)".

I agree, this is way more simple to deal with. Even though I can think 
about someone using an approach like above, he could also rewrite it like:

# ['a', 'b'].each {|item|
#  return if defined? item2module(item)
#}

return if ['a', 'b'].any?{|item|  defined? item2module(item) }

>>> * Matz prefered "return" to "a special exception that require
>>>     and load rescue",
>>>
>>>     - though some people (including ko1) prefered the latter.
>> I'm okay with raising an exception that would be rescued by require,
>> require_relative and load.
>>
>> Actually I guess this is the simpler approach and it fulfills all the
>> real use cases I could think of in this moment.
> I strongly recommended the exception approach because there are *NO*
> difficult corner cases.

Agreed.

> However, matz disagreed the exception approach because of "raise
> StopLoading is too long".  It is a kind of "name is not good".

So it would be just a matter of finding a better name, right? Not that I 
think it should make any difference because ideally only Ruby internals 
should see such errors in my opinion.

But if he thinks StopLoading is too long (while I find it short) it will 
be hard to find a shorter meaningful name I guess.

Maybe after a good night of sleep, who knows...

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:46706] Re: [ruby-trunk - Feature #4840] Allow returning from require
  2012-07-24  2:42     ` [ruby-core:46704] " Trans
@ 2012-07-24  2:49       ` Urabe Shyouhei
  2012-07-24 17:52       ` [ruby-core:46735] " Eric Hodel
  1 sibling, 0 replies; 53+ messages in thread
From: Urabe Shyouhei @ 2012-07-24  2:49 UTC (permalink / raw
  To: ruby-core

On 2012年07月24日 11:42, Trans wrote:
>>> How about redefining `__END__` to allow to call it as a method?
>>
>> It has compatibility issue that __END__ is related to DATA.
> 
> Then what about `__end__`?
> 
> Tangentially, why not deprecate __END__? Is there some really
> important use case that we just can't live without? The whole idea
> strikes me as rather hackish, especially considering it is limited to
> main file.

I'd be much appreciated if __END__ was usable from a library file.

I'd write a tiny loader script and place obfuscated script body on __END__ then.

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:46714] [ruby-trunk - Feature #4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (8 preceding siblings ...)
  2012-07-23 15:44 ` [ruby-core:46673] " alexeymuranov (Alexey Muranov)
@ 2012-07-24  7:52 ` alexeymuranov (Alexey Muranov)
  2012-07-24 15:05 ` [ruby-core:46731] " alexeymuranov (Alexey Muranov)
                   ` (17 subsequent siblings)
  27 siblings, 0 replies; 53+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2012-07-24  7:52 UTC (permalink / raw
  To: ruby-core


Issue #4840 has been updated by alexeymuranov (Alexey Muranov).


ko1 (Koichi Sasada) wrote:
> (2012/07/24 0:44), alexeymuranov (Alexey Muranov) wrote:
>  > 
>  > How about redefining `__END__` to allow to call it as a method?
>  
>  It has compatibility issue that __END__ is related to DATA.
>  
>  -- 
>  // SASADA Koichi at atdot dot net

Then a keyword `__DATA__` can be added to explicitly mark the beginning of `DATA`, what do you think?

Here is a related request: http://www.ruby-forum.com/topic/217535
----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-28381

Author: rosenfeld (Rodrigo Rosenfeld Rosas)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: 


I have a situation where there is some code in Gitorious like:

unless defined? GitoriousConfig
  # tons of lines here
end

And I would it to look like

return if defined? GitoriousConfig

#tons of lines here

It would be great to allow return from a required file or some other keyword (break, etc or a new one)


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:46731] [ruby-trunk - Feature #4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (9 preceding siblings ...)
  2012-07-24  7:52 ` [ruby-core:46714] " alexeymuranov (Alexey Muranov)
@ 2012-07-24 15:05 ` alexeymuranov (Alexey Muranov)
  2012-07-24 18:15   ` [ruby-core:46736] " Rodrigo Rosenfeld Rosas
  2012-11-24  4:39 ` [ruby-core:50010] " mame (Yusuke Endoh)
                   ` (16 subsequent siblings)
  27 siblings, 1 reply; 53+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2012-07-24 15:05 UTC (permalink / raw
  To: ruby-core


Issue #4840 has been updated by alexeymuranov (Alexey Muranov).


=begin
I propose the following behavior for `__end__` method when it is used in a block:

 [1, 2].each do |n|
   __end__
   puts n
 end
 puts 3

Output:

 1
 2

So i propose that (({__end__})) does not affect the control flow, and affect directly the source by saying something like "insert EOF after the last processed line".
=end

----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-28398

Author: rosenfeld (Rodrigo Rosenfeld Rosas)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: 


I have a situation where there is some code in Gitorious like:

unless defined? GitoriousConfig
  # tons of lines here
end

And I would it to look like

return if defined? GitoriousConfig

#tons of lines here

It would be great to allow return from a required file or some other keyword (break, etc or a new one)


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:46735] Re: [ruby-trunk - Feature #4840] Allow returning from require
  2012-07-24  2:42     ` [ruby-core:46704] " Trans
  2012-07-24  2:49       ` [ruby-core:46706] " Urabe Shyouhei
@ 2012-07-24 17:52       ` Eric Hodel
  1 sibling, 0 replies; 53+ messages in thread
From: Eric Hodel @ 2012-07-24 17:52 UTC (permalink / raw
  To: ruby-core@ruby-lang.org





On Jul 23, 2012, at 7:42 PM, Trans <transfire@gmail.com> wrote:

> why not deprecate __END__? Is there some really
> important use case that we just can't live without? The whole idea strikes me as rather hackish, especially considering it is limited to main file.

I infrequently use __END__ for single-file scripts. It's easier to transport a single file with embedded data than two or more files.

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:46736] Re: [ruby-trunk - Feature #4840] Allow returning from require
  2012-07-24 15:05 ` [ruby-core:46731] " alexeymuranov (Alexey Muranov)
@ 2012-07-24 18:15   ` Rodrigo Rosenfeld Rosas
  0 siblings, 0 replies; 53+ messages in thread
From: Rodrigo Rosenfeld Rosas @ 2012-07-24 18:15 UTC (permalink / raw
  To: ruby-core

Em 24-07-2012 12:05, alexeymuranov (Alexey Muranov) escreveu:
> Issue #4840 has been updated by alexeymuranov (Alexey Muranov).
>
>
> =begin
> I propose the following behavior for `__end__` method when it is used in a block:
>
>   [1, 2].each do |n|
>     __end__
>     puts n
>   end
>   puts 3
>
> Output:
>
>   1
>   2
>
> So i propose that (({__end__})) does not affect the control flow, and affect directly the source by saying something like "insert EOF after the last processed line".
> =end

This sounds really weird to me but I'm not against it since I can't see 
myself writing code like this ever.

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:50010] [ruby-trunk - Feature #4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (10 preceding siblings ...)
  2012-07-24 15:05 ` [ruby-core:46731] " alexeymuranov (Alexey Muranov)
@ 2012-11-24  4:39 ` mame (Yusuke Endoh)
  2012-11-24  6:26 ` [ruby-core:50024] " mame (Yusuke Endoh)
                   ` (15 subsequent siblings)
  27 siblings, 0 replies; 53+ messages in thread
From: mame (Yusuke Endoh) @ 2012-11-24  4:39 UTC (permalink / raw
  To: ruby-core


Issue #4840 has been updated by mame (Yusuke Endoh).

Target version set to 2.0.0


----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-33784

Author: rosenfeld (Rodrigo Rosenfeld Rosas)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: 2.0.0


I have a situation where there is some code in Gitorious like:

unless defined? GitoriousConfig
  # tons of lines here
end

And I would it to look like

return if defined? GitoriousConfig

#tons of lines here

It would be great to allow return from a required file or some other keyword (break, etc or a new one)


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:50024] [ruby-trunk - Feature #4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (11 preceding siblings ...)
  2012-11-24  4:39 ` [ruby-core:50010] " mame (Yusuke Endoh)
@ 2012-11-24  6:26 ` mame (Yusuke Endoh)
  2013-02-14  9:59 ` [ruby-core:52255] [ruby-trunk - Feature #4840][Feedback] " yhara (Yutaka HARA)
                   ` (14 subsequent siblings)
  27 siblings, 0 replies; 53+ messages in thread
From: mame (Yusuke Endoh) @ 2012-11-24  6:26 UTC (permalink / raw
  To: ruby-core


Issue #4840 has been updated by mame (Yusuke Endoh).


Anyone create a patch conformed to the spec written in [ruby-core:46648]?

I guess that my experimental patch ([ruby-core:36811]) is not confirmed completely;
perhaps it allows "return from class definition" (but I didn't tested yet).

-- 
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-33797

Author: rosenfeld (Rodrigo Rosenfeld Rosas)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: 2.0.0


I have a situation where there is some code in Gitorious like:

unless defined? GitoriousConfig
  # tons of lines here
end

And I would it to look like

return if defined? GitoriousConfig

#tons of lines here

It would be great to allow return from a required file or some other keyword (break, etc or a new one)


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:52255] [ruby-trunk - Feature #4840][Feedback] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (12 preceding siblings ...)
  2012-11-24  6:26 ` [ruby-core:50024] " mame (Yusuke Endoh)
@ 2013-02-14  9:59 ` yhara (Yutaka HARA)
  2013-05-09  2:14 ` [ruby-core:54874] [ruby-trunk - Feature #4840] " nobu (Nobuyoshi Nakada)
                   ` (13 subsequent siblings)
  27 siblings, 0 replies; 53+ messages in thread
From: yhara (Yutaka HARA) @ 2013-02-14  9:59 UTC (permalink / raw
  To: ruby-core


Issue #4840 has been updated by yhara (Yutaka HARA).

Status changed from Assigned to Feedback
Assignee changed from matz (Yukihiro Matsumoto) to mame (Yusuke Endoh)
Target version changed from 2.0.0 to next minor


----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-36277

Author: rosenfeld (Rodrigo Rosenfeld Rosas)
Status: Feedback
Priority: Normal
Assignee: mame (Yusuke Endoh)
Category: 
Target version: next minor


I have a situation where there is some code in Gitorious like:

unless defined? GitoriousConfig
  # tons of lines here
end

And I would it to look like

return if defined? GitoriousConfig

#tons of lines here

It would be great to allow return from a required file or some other keyword (break, etc or a new one)


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:54874] [ruby-trunk - Feature #4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (13 preceding siblings ...)
  2013-02-14  9:59 ` [ruby-core:52255] [ruby-trunk - Feature #4840][Feedback] " yhara (Yutaka HARA)
@ 2013-05-09  2:14 ` nobu (Nobuyoshi Nakada)
  2013-05-09 13:19   ` [ruby-core:54884] " Matthew Kerwin
  2013-05-09 12:42 ` [ruby-core:54882] " rosenfeld (Rodrigo Rosenfeld Rosas)
                   ` (12 subsequent siblings)
  27 siblings, 1 reply; 53+ messages in thread
From: nobu (Nobuyoshi Nakada) @ 2013-05-09  2:14 UTC (permalink / raw
  To: ruby-core


Issue #4840 has been updated by nobu (Nobuyoshi Nakada).

File 0001-compile.c-toplevel-return.patch added

A simple patch.
----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-39213

Author: rosenfeld (Rodrigo Rosenfeld Rosas)
Status: Feedback
Priority: Normal
Assignee: mame (Yusuke Endoh)
Category: 
Target version: next minor


I have a situation where there is some code in Gitorious like:

unless defined? GitoriousConfig
  # tons of lines here
end

And I would it to look like

return if defined? GitoriousConfig

#tons of lines here

It would be great to allow return from a required file or some other keyword (break, etc or a new one)


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:54882] [ruby-trunk - Feature #4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (14 preceding siblings ...)
  2013-05-09  2:14 ` [ruby-core:54874] [ruby-trunk - Feature #4840] " nobu (Nobuyoshi Nakada)
@ 2013-05-09 12:42 ` rosenfeld (Rodrigo Rosenfeld Rosas)
  2014-05-31 15:27 ` [ruby-core:62879] " nobu
                   ` (11 subsequent siblings)
  27 siblings, 0 replies; 53+ messages in thread
From: rosenfeld (Rodrigo Rosenfeld Rosas) @ 2013-05-09 12:42 UTC (permalink / raw
  To: ruby-core


Issue #4840 has been updated by rosenfeld (Rodrigo Rosenfeld Rosas).


Pretty simple, indeed :) Not that I understand it, just that I appreciate its simplicity ;)
----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-39220

Author: rosenfeld (Rodrigo Rosenfeld Rosas)
Status: Feedback
Priority: Normal
Assignee: mame (Yusuke Endoh)
Category: 
Target version: next minor


I have a situation where there is some code in Gitorious like:

unless defined? GitoriousConfig
  # tons of lines here
end

And I would it to look like

return if defined? GitoriousConfig

#tons of lines here

It would be great to allow return from a required file or some other keyword (break, etc or a new one)


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:54884] Re: [ruby-trunk - Feature #4840] Allow returning from require
  2013-05-09  2:14 ` [ruby-core:54874] [ruby-trunk - Feature #4840] " nobu (Nobuyoshi Nakada)
@ 2013-05-09 13:19   ` Matthew Kerwin
  2013-05-09 16:34     ` [ruby-core:54894] " Rodrigo Rosenfeld Rosas
  0 siblings, 1 reply; 53+ messages in thread
From: Matthew Kerwin @ 2013-05-09 13:19 UTC (permalink / raw
  To: ruby-core

[-- Attachment #1: Type: text/plain, Size: 247 bytes --]

On May 9, 2013 12:14 PM, "nobu (Nobuyoshi Nakada)" <nobu@ruby-lang.org>
wrote:
>
>
> Issue #4840 has been updated by nobu (Nobuyoshi Nakada).
>
> File 0001-compile.c-toplevel-return.patch added
>
> A simple patch.

Line 369 has a typo in "rescue"

[-- Attachment #2: Type: text/html, Size: 375 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:54892] Re: [ruby-trunk - Feature #4840] Allow returning from require
  2013-05-09 16:34     ` [ruby-core:54894] " Rodrigo Rosenfeld Rosas
@ 2013-05-09 16:28       ` Rodrigo Rosenfeld Rosas
  0 siblings, 0 replies; 53+ messages in thread
From: Rodrigo Rosenfeld Rosas @ 2013-05-09 16:28 UTC (permalink / raw
  To: ruby-core

[-- Attachment #1: Type: text/plain, Size: 563 bytes --]

Em 09-05-2013 13:27, Rodrigo Rosenfeld Rosas escreveu:
> Em 09-05-2013 10:19, Matthew Kerwin escreveu:
>>
>> On May 9, 2013 12:14 PM, "nobu (Nobuyoshi Nakada)" 
>> <nobu@ruby-lang.org <mailto:nobu@ruby-lang.org>> wrote:
>> >
>> >
>> > Issue #4840 has been updated by nobu (Nobuyoshi Nakada).
>> >
>> > File 0001-compile.c-toplevel-return.patch added
>> >
>> > A simple patch.
>>
>> Line 369 has a typo in "rescue"
>>
>
> I noticed it, but I thought it was optional to raise in case it hasn't 
> returned previously...
>
Sorry, I meant intentional, not optional.


[-- Attachment #2: Type: text/html, Size: 1267 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:54894] Re: [ruby-trunk - Feature #4840] Allow returning from require
  2013-05-09 13:19   ` [ruby-core:54884] " Matthew Kerwin
@ 2013-05-09 16:34     ` Rodrigo Rosenfeld Rosas
  2013-05-09 16:28       ` [ruby-core:54892] " Rodrigo Rosenfeld Rosas
  0 siblings, 1 reply; 53+ messages in thread
From: Rodrigo Rosenfeld Rosas @ 2013-05-09 16:34 UTC (permalink / raw
  To: ruby-core

[-- Attachment #1: Type: text/plain, Size: 444 bytes --]

Em 09-05-2013 10:19, Matthew Kerwin escreveu:
>
> On May 9, 2013 12:14 PM, "nobu (Nobuyoshi Nakada)" <nobu@ruby-lang.org 
> <mailto:nobu@ruby-lang.org>> wrote:
> >
> >
> > Issue #4840 has been updated by nobu (Nobuyoshi Nakada).
> >
> > File 0001-compile.c-toplevel-return.patch added
> >
> > A simple patch.
>
> Line 369 has a typo in "rescue"
>

I noticed it, but I thought it was optional to raise in case it hasn't 
returned previously...


[-- Attachment #2: Type: text/html, Size: 938 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:62879] [ruby-trunk - Feature #4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (15 preceding siblings ...)
  2013-05-09 12:42 ` [ruby-core:54882] " rosenfeld (Rodrigo Rosenfeld Rosas)
@ 2014-05-31 15:27 ` nobu
  2014-06-26 12:33 ` [ruby-core:63341] " rr.rosas
                   ` (10 subsequent siblings)
  27 siblings, 0 replies; 53+ messages in thread
From: nobu @ 2014-05-31 15:27 UTC (permalink / raw
  To: ruby-core

Issue #4840 has been updated by Nobuyoshi Nakada.

Description updated

----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-46991

* Author: Rodrigo Rosenfeld Rosas
* Status: Feedback
* Priority: Normal
* Assignee: Yusuke Endoh
* Category: 
* Target version: next minor
----------------------------------------
I have a situation where there is some code in Gitorious like:

~~~ruby
unless defined? GitoriousConfig
  # tons of lines here
end
~~~

And I would it to look like

~~~ruby
return if defined? GitoriousConfig

#tons of lines here
~~~

It would be great to allow return from a required file or some other keyword (break, etc or a new one)

---Files--------------------------------
feature-4840.odp (114 KB)
0001-compile.c-toplevel-return.patch (1.71 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:63341] [ruby-trunk - Feature #4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (16 preceding siblings ...)
  2014-05-31 15:27 ` [ruby-core:62879] " nobu
@ 2014-06-26 12:33 ` rr.rosas
  2014-06-26 13:04 ` [ruby-core:63346] " mame
                   ` (9 subsequent siblings)
  27 siblings, 0 replies; 53+ messages in thread
From: rr.rosas @ 2014-06-26 12:33 UTC (permalink / raw
  To: ruby-core

Issue #4840 has been updated by Rodrigo Rosenfeld Rosas.


Yusuke, would the patch proposed by Nobu with the typo fix for rescue be good enough?

----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-47388

* Author: Rodrigo Rosenfeld Rosas
* Status: Feedback
* Priority: Normal
* Assignee: Yusuke Endoh
* Category: 
* Target version: next minor
----------------------------------------
I have a situation where there is some code in Gitorious like:

~~~ruby
unless defined? GitoriousConfig
  # tons of lines here
end
~~~

And I would it to look like

~~~ruby
return if defined? GitoriousConfig

#tons of lines here
~~~

It would be great to allow return from a required file or some other keyword (break, etc or a new one)

---Files--------------------------------
feature-4840.odp (114 KB)
0001-compile.c-toplevel-return.patch (1.71 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:63346] [ruby-trunk - Feature #4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (17 preceding siblings ...)
  2014-06-26 12:33 ` [ruby-core:63341] " rr.rosas
@ 2014-06-26 13:04 ` mame
  2015-11-09  6:34 ` [ruby-core:71392] [Ruby trunk " ko1
                   ` (8 subsequent siblings)
  27 siblings, 0 replies; 53+ messages in thread
From: mame @ 2014-06-26 13:04 UTC (permalink / raw
  To: ruby-core

Issue #4840 has been updated by Yusuke Endoh.

Assignee changed from Yusuke Endoh to Nobuyoshi Nakada

I trust nobu more than myself.  Thank you!

-- 
Yusuke Endoh <mame@ruby-lang.org>

----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-47393

* Author: Rodrigo Rosenfeld Rosas
* Status: Feedback
* Priority: Normal
* Assignee: Nobuyoshi Nakada
* Category: 
* Target version: next minor
----------------------------------------
I have a situation where there is some code in Gitorious like:

~~~ruby
unless defined? GitoriousConfig
  # tons of lines here
end
~~~

And I would it to look like

~~~ruby
return if defined? GitoriousConfig

#tons of lines here
~~~

It would be great to allow return from a required file or some other keyword (break, etc or a new one)

---Files--------------------------------
feature-4840.odp (114 KB)
0001-compile.c-toplevel-return.patch (1.71 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:71392] [Ruby trunk - Feature #4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (18 preceding siblings ...)
  2014-06-26 13:04 ` [ruby-core:63346] " mame
@ 2015-11-09  6:34 ` ko1
  2015-11-09 10:54 ` [ruby-core:71413] " rr.rosas
                   ` (7 subsequent siblings)
  27 siblings, 0 replies; 53+ messages in thread
From: ko1 @ 2015-11-09  6:34 UTC (permalink / raw
  To: ruby-core

Issue #4840 has been updated by Koichi Sasada.


Discussion: https://docs.google.com/document/d/1D0Eo5N7NE_unIySOKG9lVj_eyXf66BQPM4PKp7NvMyQ/pub

Feel free to add your comments.

----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-54761

* Author: Rodrigo Rosenfeld Rosas
* Status: Feedback
* Priority: Normal
* Assignee: Nobuyoshi Nakada
----------------------------------------
I have a situation where there is some code in Gitorious like:

~~~ruby
unless defined? GitoriousConfig
  # tons of lines here
end
~~~

And I would it to look like

~~~ruby
return if defined? GitoriousConfig

#tons of lines here
~~~

It would be great to allow return from a required file or some other keyword (break, etc or a new one)

---Files--------------------------------
feature-4840.odp (114 KB)
0001-compile.c-toplevel-return.patch (1.71 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:71413] [Ruby trunk - Feature #4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (19 preceding siblings ...)
  2015-11-09  6:34 ` [ruby-core:71392] [Ruby trunk " ko1
@ 2015-11-09 10:54 ` rr.rosas
  2016-08-02  2:45 ` [ruby-core:76654] [Ruby trunk Feature#4840] " nobu
                   ` (6 subsequent siblings)
  27 siblings, 0 replies; 53+ messages in thread
From: rr.rosas @ 2015-11-09 10:54 UTC (permalink / raw
  To: ruby-core

Issue #4840 has been updated by Rodrigo Rosenfeld Rosas.


Thanks for the update, but I'd like to point out the description in that document is not accurate:

~~~
### Before
unless cond
  class C
  end
end
# … or …
class C
end unless cond
~~~

This is like the actual code looks like (the one that motivated this feature request):

https://github.com/grjones/gitorious-submodule-dependencies/blob/master/config/initializers/gitorious_config.rb

~~~
unless defined? GitoriousConfig
  GitoriousConfig = c = YAML::load_file(File.join(Rails.root,"config/gitorious.yml"))[RAILS_ENV]

  # make the default be publicly open
  GitoriousConfig["public_mode"] = true if GitoriousConfig["public_mode"].nil?

  # ...
~~~

As you can see, the assumption that we would be dealing with a conditional single class declaration is false, so, the alternative proposal for currently handling this situation does not really apply in several cases.

----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-54782

* Author: Rodrigo Rosenfeld Rosas
* Status: Feedback
* Priority: Normal
* Assignee: Nobuyoshi Nakada
----------------------------------------
I have a situation where there is some code in Gitorious like:

~~~ruby
unless defined? GitoriousConfig
  # tons of lines here
end
~~~

And I would it to look like

~~~ruby
return if defined? GitoriousConfig

#tons of lines here
~~~

It would be great to allow return from a required file or some other keyword (break, etc or a new one)

---Files--------------------------------
feature-4840.odp (114 KB)
0001-compile.c-toplevel-return.patch (1.71 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:76654] [Ruby trunk Feature#4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (20 preceding siblings ...)
  2015-11-09 10:54 ` [ruby-core:71413] " rr.rosas
@ 2016-08-02  2:45 ` nobu
  2016-08-03 19:30 ` [ruby-core:76688] " rr.rosas
                   ` (5 subsequent siblings)
  27 siblings, 0 replies; 53+ messages in thread
From: nobu @ 2016-08-02  2:45 UTC (permalink / raw
  To: ruby-core

Issue #4840 has been updated by Nobuyoshi Nakada.


Stalling due to unresolved bugs.

Current status: https://gist.github.com/nobu/e70b0c897b12b936e063

----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-59874

* Author: Rodrigo Rosenfeld Rosas
* Status: Feedback
* Priority: Normal
* Assignee: Nobuyoshi Nakada
----------------------------------------
I have a situation where there is some code in Gitorious like:

~~~ruby
unless defined? GitoriousConfig
  # tons of lines here
end
~~~

And I would it to look like

~~~ruby
return if defined? GitoriousConfig

#tons of lines here
~~~

It would be great to allow return from a required file or some other keyword (break, etc or a new one)

---Files--------------------------------
feature-4840.odp (114 KB)
0001-compile.c-toplevel-return.patch (1.71 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:76688] [Ruby trunk Feature#4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (21 preceding siblings ...)
  2016-08-02  2:45 ` [ruby-core:76654] [Ruby trunk Feature#4840] " nobu
@ 2016-08-03 19:30 ` rr.rosas
  2016-08-10  2:51 ` [ruby-core:76805] " shyouhei
                   ` (4 subsequent siblings)
  27 siblings, 0 replies; 53+ messages in thread
From: rr.rosas @ 2016-08-03 19:30 UTC (permalink / raw
  To: ruby-core

Issue #4840 has been updated by Rodrigo Rosenfeld Rosas.


I'm not sure I understand that link. What is 1, 2, 3 and 4? What are the bugs?

----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-59904

* Author: Rodrigo Rosenfeld Rosas
* Status: Feedback
* Priority: Normal
* Assignee: Nobuyoshi Nakada
----------------------------------------
I have a situation where there is some code in Gitorious like:

~~~ruby
unless defined? GitoriousConfig
  # tons of lines here
end
~~~

And I would it to look like

~~~ruby
return if defined? GitoriousConfig

#tons of lines here
~~~

It would be great to allow return from a required file or some other keyword (break, etc or a new one)

---Files--------------------------------
feature-4840.odp (114 KB)
0001-compile.c-toplevel-return.patch (1.71 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:76805] [Ruby trunk Feature#4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (22 preceding siblings ...)
  2016-08-03 19:30 ` [ruby-core:76688] " rr.rosas
@ 2016-08-10  2:51 ` shyouhei
  2017-08-28 15:49 ` [ruby-core:82488] " headius
                   ` (3 subsequent siblings)
  27 siblings, 0 replies; 53+ messages in thread
From: shyouhei @ 2016-08-10  2:51 UTC (permalink / raw
  To: ruby-core

Issue #4840 has been updated by Shyouhei Urabe.


We looked at this issue at yesterday's developer meeting.  No problem to introduce this feature was reported, except it is not implemented yet.  Nobu tried this before and had technical difficulty; not sure if that could be rerouted.  We are basically waiting for him (&others) to complete.

----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-60026

* Author: Rodrigo Rosenfeld Rosas
* Status: Feedback
* Priority: Normal
* Assignee: Nobuyoshi Nakada
----------------------------------------
I have a situation where there is some code in Gitorious like:

~~~ruby
unless defined? GitoriousConfig
  # tons of lines here
end
~~~

And I would it to look like

~~~ruby
return if defined? GitoriousConfig

#tons of lines here
~~~

It would be great to allow return from a required file or some other keyword (break, etc or a new one)

---Files--------------------------------
feature-4840.odp (114 KB)
0001-compile.c-toplevel-return.patch (1.71 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:82488] [Ruby trunk Feature#4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (23 preceding siblings ...)
  2016-08-10  2:51 ` [ruby-core:76805] " shyouhei
@ 2017-08-28 15:49 ` headius
  2017-08-28 16:49 ` [ruby-core:82490] " nobu
                   ` (2 subsequent siblings)
  27 siblings, 0 replies; 53+ messages in thread
From: headius @ 2017-08-28 15:49 UTC (permalink / raw
  To: ruby-core

Issue #4840 has been updated by headius (Charles Nutter).


Were any tests or specs added for this feature? I don't see anything recent added to language/return_spec.rb and the related commits don't show any additions to MRI's tests.

I believe we need at least one of these to be filled out. I'd be happy to do it but this is a very long thread and I'm not sure what is or is not considered spec.

----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-66299

* Author: rosenfeld (Rodrigo Rosenfeld Rosas)
* Status: Closed
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version: 
----------------------------------------
I have a situation where there is some code in Gitorious like:

~~~ruby
unless defined? GitoriousConfig
  # tons of lines here
end
~~~

And I would it to look like

~~~ruby
return if defined? GitoriousConfig

#tons of lines here
~~~

It would be great to allow return from a required file or some other keyword (break, etc or a new one)

---Files--------------------------------
feature-4840.odp (114 KB)
0001-compile.c-toplevel-return.patch (1.71 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:82490] [Ruby trunk Feature#4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (24 preceding siblings ...)
  2017-08-28 15:49 ` [ruby-core:82488] " headius
@ 2017-08-28 16:49 ` nobu
  2017-08-28 19:36 ` [ruby-core:82491] " headius
  2017-12-15 14:21 ` [ruby-core:84289] " rr.rosas
  27 siblings, 0 replies; 53+ messages in thread
From: nobu @ 2017-08-28 16:49 UTC (permalink / raw
  To: ruby-core

Issue #4840 has been updated by nobu (Nobuyoshi Nakada).


test/ruby/test_syntax.rb:test_return_toplevel

----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-66301

* Author: rosenfeld (Rodrigo Rosenfeld Rosas)
* Status: Closed
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version: 
----------------------------------------
I have a situation where there is some code in Gitorious like:

~~~ruby
unless defined? GitoriousConfig
  # tons of lines here
end
~~~

And I would it to look like

~~~ruby
return if defined? GitoriousConfig

#tons of lines here
~~~

It would be great to allow return from a required file or some other keyword (break, etc or a new one)

---Files--------------------------------
feature-4840.odp (114 KB)
0001-compile.c-toplevel-return.patch (1.71 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:82491] [Ruby trunk Feature#4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (25 preceding siblings ...)
  2017-08-28 16:49 ` [ruby-core:82490] " nobu
@ 2017-08-28 19:36 ` headius
  2017-12-15 14:21 ` [ruby-core:84289] " rr.rosas
  27 siblings, 0 replies; 53+ messages in thread
From: headius @ 2017-08-28 19:36 UTC (permalink / raw
  To: ruby-core

Issue #4840 has been updated by headius (Charles Nutter).


Ahh great, thank you for the pointer, nobu!

----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-66302

* Author: rosenfeld (Rodrigo Rosenfeld Rosas)
* Status: Closed
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version: 
----------------------------------------
I have a situation where there is some code in Gitorious like:

~~~ruby
unless defined? GitoriousConfig
  # tons of lines here
end
~~~

And I would it to look like

~~~ruby
return if defined? GitoriousConfig

#tons of lines here
~~~

It would be great to allow return from a required file or some other keyword (break, etc or a new one)

---Files--------------------------------
feature-4840.odp (114 KB)
0001-compile.c-toplevel-return.patch (1.71 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [ruby-core:84289] [Ruby trunk Feature#4840] Allow returning from require
  2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
                   ` (26 preceding siblings ...)
  2017-08-28 19:36 ` [ruby-core:82491] " headius
@ 2017-12-15 14:21 ` rr.rosas
  27 siblings, 0 replies; 53+ messages in thread
From: rr.rosas @ 2017-12-15 14:21 UTC (permalink / raw
  To: ruby-core

Issue #4840 has been updated by rosenfeld (Rodrigo Rosenfeld Rosas).


Could someone please explain me what is the current status of this feature? I thought I would be able to return from the top-level when requiring a file, but it still seems to be an invalid syntax to this day. Am I missing something?

----------------------------------------
Feature #4840: Allow returning from require
https://bugs.ruby-lang.org/issues/4840#change-68446

* Author: rosenfeld (Rodrigo Rosenfeld Rosas)
* Status: Closed
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version: 
----------------------------------------
I have a situation where there is some code in Gitorious like:

~~~ruby
unless defined? GitoriousConfig
  # tons of lines here
end
~~~

And I would it to look like

~~~ruby
return if defined? GitoriousConfig

#tons of lines here
~~~

It would be great to allow return from a required file or some other keyword (break, etc or a new one)

---Files--------------------------------
feature-4840.odp (114 KB)
0001-compile.c-toplevel-return.patch (1.71 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 53+ messages in thread

end of thread, other threads:[~2017-12-15 14:21 UTC | newest]

Thread overview: 53+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-06 14:11 [ruby-core:36785] [Ruby 1.9 - Feature #4840][Open] Allow returning from require Rodrigo Rosenfeld Rosas
2011-06-06 14:18 ` [ruby-core:36786] " Michael Edgar
2011-06-06 15:00   ` [ruby-core:36793] " Magnus Holm
2011-06-06 22:08   ` [ruby-core:36804] " Clifford Heath
2011-06-07  8:14     ` [ruby-core:36807] " Haase, Konstantin
2011-06-07 11:19       ` [ruby-core:36816] " Rodrigo Rosenfeld Rosas
2011-06-07 10:10 ` [ruby-core:36811] " Yusuke ENDOH
2011-06-07 11:15   ` [ruby-core:36815] " Rodrigo Rosenfeld Rosas
2011-06-07 11:36     ` [ruby-core:36817] " Yusuke ENDOH
2011-06-08  0:33   ` [ruby-core:36830] " Yukihiro Matsumoto
2011-06-08  7:38     ` [ruby-core:36831] " Charles Oliver Nutter
2011-06-08  8:43       ` [ruby-core:36837] " Adam Prescott
2011-06-08  9:22     ` [ruby-core:36839] " Ryan Davis
2011-06-08  9:24       ` [ruby-core:36840] " Charles Oliver Nutter
2011-06-08 11:57     ` [ruby-core:36844] " Alex Young
2011-06-08 12:00       ` [ruby-core:36845] " Haase, Konstantin
2012-03-25  7:10 ` [ruby-core:43632] [ruby-trunk - Feature #4840][Assigned] " mame (Yusuke Endoh)
2012-03-25 15:07 ` [ruby-core:43667] [ruby-trunk - Feature #4840] " trans (Thomas Sawyer)
2012-06-07 17:38 ` [ruby-core:45482] " rosenfeld (Rodrigo Rosenfeld Rosas)
2012-06-07 23:00 ` [ruby-core:45493] " mame (Yusuke Endoh)
2012-06-08 12:51 ` [ruby-core:45511] " rosenfeld (Rodrigo Rosenfeld Rosas)
2012-07-23 13:12 ` [ruby-core:46648] " mame (Yusuke Endoh)
2012-07-23 14:57   ` [ruby-core:46667] " Rodrigo Rosenfeld Rosas
2012-07-24  1:37     ` [ruby-core:46702] " SASADA Koichi
2012-07-24  2:47       ` [ruby-core:46705] " Rodrigo Rosenfeld Rosas
2012-07-23 15:44 ` [ruby-core:46673] " alexeymuranov (Alexey Muranov)
2012-07-24  1:26   ` [ruby-core:46701] " SASADA Koichi
2012-07-24  2:42     ` [ruby-core:46704] " Trans
2012-07-24  2:49       ` [ruby-core:46706] " Urabe Shyouhei
2012-07-24 17:52       ` [ruby-core:46735] " Eric Hodel
2012-07-24  7:52 ` [ruby-core:46714] " alexeymuranov (Alexey Muranov)
2012-07-24 15:05 ` [ruby-core:46731] " alexeymuranov (Alexey Muranov)
2012-07-24 18:15   ` [ruby-core:46736] " Rodrigo Rosenfeld Rosas
2012-11-24  4:39 ` [ruby-core:50010] " mame (Yusuke Endoh)
2012-11-24  6:26 ` [ruby-core:50024] " mame (Yusuke Endoh)
2013-02-14  9:59 ` [ruby-core:52255] [ruby-trunk - Feature #4840][Feedback] " yhara (Yutaka HARA)
2013-05-09  2:14 ` [ruby-core:54874] [ruby-trunk - Feature #4840] " nobu (Nobuyoshi Nakada)
2013-05-09 13:19   ` [ruby-core:54884] " Matthew Kerwin
2013-05-09 16:34     ` [ruby-core:54894] " Rodrigo Rosenfeld Rosas
2013-05-09 16:28       ` [ruby-core:54892] " Rodrigo Rosenfeld Rosas
2013-05-09 12:42 ` [ruby-core:54882] " rosenfeld (Rodrigo Rosenfeld Rosas)
2014-05-31 15:27 ` [ruby-core:62879] " nobu
2014-06-26 12:33 ` [ruby-core:63341] " rr.rosas
2014-06-26 13:04 ` [ruby-core:63346] " mame
2015-11-09  6:34 ` [ruby-core:71392] [Ruby trunk " ko1
2015-11-09 10:54 ` [ruby-core:71413] " rr.rosas
2016-08-02  2:45 ` [ruby-core:76654] [Ruby trunk Feature#4840] " nobu
2016-08-03 19:30 ` [ruby-core:76688] " rr.rosas
2016-08-10  2:51 ` [ruby-core:76805] " shyouhei
2017-08-28 15:49 ` [ruby-core:82488] " headius
2017-08-28 16:49 ` [ruby-core:82490] " nobu
2017-08-28 19:36 ` [ruby-core:82491] " headius
2017-12-15 14:21 ` [ruby-core:84289] " rr.rosas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).