Project

General

Profile

Actions

Feature #9405

closed

Implicitly convert blocks to procs / remove blocks completely?

Added by alexeymuranov (Alexey Muranov) about 10 years ago. Updated over 2 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:<unknown>]

Description

While i am think of this, here is one more proposal.

If a block appears in a place where no block can appear, convert it automatically to a proc. For example:

p = do |n; s| s = gets; n.times do puts s end end
t = {|| Time.now }

When a block takes no arguments and is written with curly braces, to distinguish it easily from a hash (or from a set, who knows? #5478 :)), it would need to open with {||.


Maybe ultimately blocks can be completely replaced by procs and lambdas from user's perspective and only existe for the compiler. Unfortunately, for compatibility, this would require treating specially literal procs in method calls (differently from procs and lambdas passed as variable or expression values. The semantics of

foo(1) { |n| ... }

can be the following: the literal proc is converted to a block (which user never "sees") because it appears in a method call where no more arguments can appear.

Actions #1

Updated by nobu (Nobuyoshi Nakada) about 10 years ago

  • Status changed from Open to Rejected

It's the idea once implemented and abandoned.

Actions #2

Updated by hsbt (Hiroshi SHIBATA) over 2 years ago

  • Project changed from 14 to Ruby master
Actions

Also available in: Atom PDF

Like0
Like0Like0