Feature #6354

Remove escape (break/return/redo/next support) from class/module scope

Added by Koichi Sasada almost 2 years ago. Updated over 1 year ago.

[ruby-core:44612]
Status:Assigned
Priority:Normal
Assignee:Yukihiro Matsumoto
Category:-
Target version:next minor

Description

Let's remove global escape (break/return/redo/next support) from class/module scope.

Yes, it introduces incompatibility. However, anyone use it?
I think the following examples are evil (difficult to understand).

# examples:
1.times{
class C
break # break from 1.times
end
}

1.times{
class C
module M
break # break from 1.times
end
end
}

3.times{|n|
p n # repeat print 0
class C
redo
end
}

->{
class C
return return from outer lambda block
end
}.call

->{
proc{
class C
return # return from outer lambda (not proc) block
end
}.call
}.call

etc, etc.

History

#1 Updated by Yusuke Endoh almost 2 years ago

  • Status changed from Open to Assigned

I don't object, but just curious.
By removing it, what advantage will we get?

Yusuke Endoh mame@tsg.ne.jp

#2 Updated by Koichi Sasada almost 2 years ago

(2012/04/25 12:37), mame (Yusuke Endoh) wrote:

By removing it, what advantage will we get?

It simplifies VM implementation.

--
// SASADA Koichi at atdot dot net

#3 Updated by Kazuki Tsujimoto almost 2 years ago

What about yield?
I think it should also be removed if the proposal is accepted.

#4 Updated by Koichi Sasada almost 2 years ago

(2012/04/28 0:37), ktsj (Kazuki Tsujimoto) wrote:

What about yield?
I think it should also be removed if the proposal is accepted.

Example?

--
// SASADA Koichi at atdot dot net

#5 Updated by Kazuki Tsujimoto almost 2 years ago

Such as:

def f
class << self
yield
end
end

#6 Updated by Koichi Sasada almost 2 years ago

(2012/04/30 10:16), ktsj (Kazuki Tsujimoto) wrote:

Issue #6354 has been updated by ktsj (Kazuki Tsujimoto).

Such as:

def f
class << self
yield
end
end

Ah, singleton class... I agree with you.

BTW, the following code causes syntax error. It is inconsistency.

def m
1.times{
class << ''
break
end
}
end

--
// SASADA Koichi at atdot dot net

#7 Updated by Koichi Sasada over 1 year ago

  • Target version set to next minor

Also available in: Atom PDF