Project

General

Profile

Feature #9405

Implicitly convert blocks to procs / remove blocks completely?

Added by alexeymuranov (Alexey Muranov) about 6 years ago. Updated about 6 years ago.

Status:
Rejected
Priority:
Normal
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.

#1

Updated by nobu (Nobuyoshi Nakada) about 6 years ago

  • Status changed from Open to Rejected

It's the idea once implemented and abandoned.

Also available in: Atom PDF