REQUEST FOR COMMENTS: Change to future Ruby hash literal syntax

In 1.9, if you prefer to omit parentheses and you write this:

  h = { a: Array.new 5, 'A', b: 0, c: 1 }   # Syntax error

you will get a syntax error.  The following works:

  h = { a: Array.new(5, 'A'), b: 0, c: 1 }

because the parser is not confused by the argument-separating comma
and the element-separating comma.

I propose that the owners consider changing the syntax.

ALTERNATIVE 1: Same input, different interpretation

If the scanner does lookahead and returns tASSOC_SEP for a comma
that is followed by a label, then there is no ambiguity.

ALTERNATIVE 2:  Use ';' to separate elements, use ',' for arguments

  h = { a: Array.new 5, 'A'; b: 0; c: 1 }   # Proposal 2

This avoids shift-reduce conflicts by a simple change to the assocs
production in parse.y, perhaps.  Unfortunately the semicolon looks
strange, especially in array literals, when we address those, too.

ALTERNATIVE 3: Allow ';' as an element separator, but keep ','

 h = { a: Array.new 5, 'A'; b: 0, c: 1 }    # Proposal 3

This does not break working code.  It is like 'or' versus '||',
and 'do' vs. '{', i.e., same role, different precedence.

-- 
Posted via http://www.ruby-forum.com/.