[#4595] New block syntax — Daniel Amelang <daniel.amelang@...>

I'm really sorry if this isn't the place to talk about this. I've

25 messages 2005/03/21
[#4606] Re: New block syntax — "David A. Black" <dblack@...> 2005/03/21

Hi --

[#4629] Re: New block syntax — "Sean E. Russell" <ser@...> 2005/03/30

On Monday 21 March 2005 16:17, David A. Black wrote:

[#4648] about REXML::Encoding — speakillof <speakillof@...>

Hi.

15 messages 2005/03/31
[#4659] Re: about REXML::Encoding — "Sean E. Russell" <ser@...> 2005/04/04

On Thursday 31 March 2005 09:44, speakillof wrote:

New block syntax

From: Daniel Amelang <daniel.amelang@...>
Date: 2005-03-21 02:31:05 UTC
List: ruby-core #4595
I'm really sorry if this isn't the place to talk about this. I've
already brought it up on ruby-talk, but I think ruby-core is where the
people involved in the issue are.

I really like the new proposed syntax for proc/blocks:

b = {|| puts "good idea"}

But the empty pipes make it ungraceful, in my opinion. I understand
the need to differentiate between the {} syntax for blocks and the {}
syntax for hashes. Thus, I propose that instead of changing the block
syntax to resolve the ambiguity, we change the hash syntax.

Consider the following alternative hash constructs:

# The key value pairs completely differentiate the hash from an array,
# allowing us to borrow the [] from array's constructor
hash = [name:'bill', age:25]

# So what does an empty hash look like? Here's one possiblility.
hash = [:]

If the preceding syntax were adopted, the {} braces would no longer
partially belong to hash, but entirely to blocks/procs, giving us much
needed flexibility in syntax.

# Now this works!
b = { puts "good idea?" }

# This is a method call with an empty hash as an argument,
# and a block passed in.
# The current way of doing this is do_it({}) {} , which isn't that bad.
do_it [:] {}

Just an alternative to the current approach. Thanks for your attention!

Dan

In This Thread

Prev Next