Forum: Ruby-core [ruby-trunk - Feature #7882][Open] Allow rescue/else/ensure in do..end

Posted by charliesome (Charlie Somerville) (Guest)
on 2013-02-19 07:00
(Received via mailing list)
Issue #7882 has been reported by charliesome (Charlie Somerville).

----------------------------------------
Feature #7882: Allow rescue/else/ensure in do..end
https://bugs.ruby-lang.org/issues/7882

Author: charliesome (Charlie Somerville)
Status: Open
Priority: Normal
Assignee:
Category:
Target version: 2.1.0


=begin
The keywords (({rescue})), (({else})) and (({ensure})) can be used when 
defining methods like so:

  def foo
    #
  rescue
    #
  else
    #
  ensure
    #
  end

However when using a block delimited by do..end, you must use 
(({begin}))..(({end})) as well:

  foo do
    begin
      # ...
    rescue
      # ...
      # ...
    end
  end

It would be nice to be able to drop the extra (({begin}))..(({end})) and 
use (({rescue})), etc. clauses directly:

  foo do
    # ...
  rescue
    # ...
    # ...
  end

I cannot think of any ambiguities this syntax would cause, but please 
correct me if I am wrong.
=end
Posted by Nobuyoshi Nakada (nobu)
on 2013-02-19 14:48
(Received via mailing list)
Issue #7882 has been updated by nobu (Nobuyoshi Nakada).


=begin
I remember I've seen the same proposal.

What do you think about {} block?

  foo {
    ...
  rescue
    ...
  }

seems odd to me a little.

Or improve (({do}))...(({end})) only?
=end

----------------------------------------
Feature #7882: Allow rescue/else/ensure in do..end
https://bugs.ruby-lang.org/issues/7882#change-36614

Author: charliesome (Charlie Somerville)
Status: Open
Priority: Normal
Assignee:
Category:
Target version: 2.1.0


=begin
The keywords (({rescue})), (({else})) and (({ensure})) can be used when 
defining methods like so:

  def foo
    #
  rescue
    #
  else
    #
  ensure
    #
  end

However when using a block delimited by do..end, you must use 
(({begin}))..(({end})) as well:

  foo do
    begin
      # ...
    rescue
      # ...
      # ...
    end
  end

It would be nice to be able to drop the extra (({begin}))..(({end})) and 
use (({rescue})), etc. clauses directly:

  foo do
    # ...
  rescue
    # ...
    # ...
  end

I cannot think of any ambiguities this syntax would cause, but please 
correct me if I am wrong.
=end
Posted by rosenfeld (Rodrigo Rosenfeld Rosas) (Guest)
on 2013-02-19 14:55
(Received via mailing list)
Issue #7882 has been updated by rosenfeld (Rodrigo Rosenfeld Rosas).


I don't find it that odd, Nobu, although I think most developers would 
tend to use do-end anyway as we usually do in Ruby when the block span 
multiple lines.

I like the idea very much actually.
----------------------------------------
Feature #7882: Allow rescue/else/ensure in do..end
https://bugs.ruby-lang.org/issues/7882#change-36615

Author: charliesome (Charlie Somerville)
Status: Open
Priority: Normal
Assignee:
Category:
Target version: 2.1.0


=begin
The keywords (({rescue})), (({else})) and (({ensure})) can be used when 
defining methods like so:

  def foo
    #
  rescue
    #
  else
    #
  ensure
    #
  end

However when using a block delimited by do..end, you must use 
(({begin}))..(({end})) as well:

  foo do
    begin
      # ...
    rescue
      # ...
      # ...
    end
  end

It would be nice to be able to drop the extra (({begin}))..(({end})) and 
use (({rescue})), etc. clauses directly:

  foo do
    # ...
  rescue
    # ...
    # ...
  end

I cannot think of any ambiguities this syntax would cause, but please 
correct me if I am wrong.
=end
Posted by mame (Yusuke Endoh) (Guest)
on 2013-02-19 15:52
(Received via mailing list)
Issue #7882 has been updated by mame (Yusuke Endoh).

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

I have suggested the same proposal (in Japanese [ruby-dev:31393]).
Matz said in [ruby-dev:31423] that it is not clear (to him) whether:

  loop do
    :
  rescue
    :
  ensure
    :
  end

should behave like:

  begin
    loop do
      :
    end
  rescue
    :
  ensure
    :
  end

or:

  loop do
    begin
      :
    rescue
      :
    ensure
      :
    end
  end

--
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Feature #7882: Allow rescue/else/ensure in do..end
https://bugs.ruby-lang.org/issues/7882#change-36620

Author: charliesome (Charlie Somerville)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: 2.1.0


=begin
The keywords (({rescue})), (({else})) and (({ensure})) can be used when 
defining methods like so:

  def foo
    #
  rescue
    #
  else
    #
  ensure
    #
  end

However when using a block delimited by do..end, you must use 
(({begin}))..(({end})) as well:

  foo do
    begin
      # ...
    rescue
      # ...
      # ...
    end
  end

It would be nice to be able to drop the extra (({begin}))..(({end})) and 
use (({rescue})), etc. clauses directly:

  foo do
    # ...
  rescue
    # ...
    # ...
  end

I cannot think of any ambiguities this syntax would cause, but please 
correct me if I am wrong.
=end
Posted by alexeymuranov (Alexey Muranov) (Guest)
on 2013-02-19 16:08
(Received via mailing list)
Issue #7882 has been updated by alexeymuranov (Alexey Muranov).


I've heard of a convention to use `{ ... }` for blocks evaluated for a 
result and `do ... end` for blocks evaluated for side effects: 
http://onestepback.org/index.cgi/Tech/Ruby/BraceVsDoEnd.rdoc
From this point of view, there probably shouldn't be any differences in 
the syntax inside the two forms of blocks.
----------------------------------------
Feature #7882: Allow rescue/else/ensure in do..end
https://bugs.ruby-lang.org/issues/7882#change-36621

Author: charliesome (Charlie Somerville)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: 2.1.0


=begin
The keywords (({rescue})), (({else})) and (({ensure})) can be used when 
defining methods like so:

  def foo
    #
  rescue
    #
  else
    #
  ensure
    #
  end

However when using a block delimited by do..end, you must use 
(({begin}))..(({end})) as well:

  foo do
    begin
      # ...
    rescue
      # ...
      # ...
    end
  end

It would be nice to be able to drop the extra (({begin}))..(({end})) and 
use (({rescue})), etc. clauses directly:

  foo do
    # ...
  rescue
    # ...
    # ...
  end

I cannot think of any ambiguities this syntax would cause, but please 
correct me if I am wrong.
=end
Posted by rosenfeld (Rodrigo Rosenfeld Rosas) (Guest)
on 2013-02-19 16:39
(Received via mailing list)
Issue #7882 has been updated by rosenfeld (Rodrigo Rosenfeld Rosas).


Yusuke, I believe it should be the latter. If you want to rescue from 
the yielding method you have the option of doing it like this in most 
cases:

  with_transaction do
    ...
  rescue
    ...
  end rescue puts 'with_transaction raised outside the yield block'

----------------------------------------
Feature #7882: Allow rescue/else/ensure in do..end
https://bugs.ruby-lang.org/issues/7882#change-36622

Author: charliesome (Charlie Somerville)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: 2.1.0


=begin
The keywords (({rescue})), (({else})) and (({ensure})) can be used when 
defining methods like so:

  def foo
    #
  rescue
    #
  else
    #
  ensure
    #
  end

However when using a block delimited by do..end, you must use 
(({begin}))..(({end})) as well:

  foo do
    begin
      # ...
    rescue
      # ...
      # ...
    end
  end

It would be nice to be able to drop the extra (({begin}))..(({end})) and 
use (({rescue})), etc. clauses directly:

  foo do
    # ...
  rescue
    # ...
    # ...
  end

I cannot think of any ambiguities this syntax would cause, but please 
correct me if I am wrong.
=end
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.