Comma separated lists syntax error

I’m very disappointed that I cannot format my hashes like this
{ :a => 1
, :b => 2
, :c => 3
}
The technique is popular in the haskell community; it has some obvious
benefits over the traditional
{ :a => 1,
:b => 2,
:c => 3
}
It doesn’t work in 1.9 either.

ry

On Dec 12, 5:11 pm, ry dahl [email protected] wrote:

}
It doesn’t work in 1.9 either.

For the same obvious reasons as you desire that, does it sufficiently
please you that this alternate markup works:

C:>type tmp.rb
h = {
:a => 1,
:b => 2,
:c => 3,
}

p h

C:>ruby tmp.rb
{:c=>3, :a=>1, :b=>2}

On 12/13/07, ry dahl [email protected] wrote:

}
Just out of curiosity, what are those obvious benefits? It’s the first
time I’ve seen somebody prefer commas at the beginning of a new row.

No, the benefit is that the separators are at the beginning of the
elements, aligned and in the same column so that it is easy to see one
is not missing, you also don’t need to maintain the commas at the end
of the line.

Andrei M. wrote:

:c => 3

}

Just out of curiosity, what are those obvious benefits? It’s the first
time I’ve seen somebody prefer commas at the beginning of a new row.

I do this with C code. The idea is that you should make a continuation
(here I use “continuation” to mean the 2nd and subsequent parts of a
single statement that is broken over several lines) visually distinct by
starting the continuation with a token that can’t legitimately start a
new statement. I found the argument persuasive for C code.

In Ruby, though, a comma at the end of a line is one of the ways to tell
the parser that the statement is continued on the next line. Okay,
different language, different rules. Nothing to get your panties in a
wad about.

Of course, I cut my teeth on FORTRAN, which used a non-blank character
in column 1 to indicate a continuation, so my standards probably aren’t
as high as they should be.

Hi,

At Thu, 13 Dec 2007 10:26:21 +0900,
ry dahl wrote in [ruby-talk:283285]:

No, the benefit is that the separators are at the beginning of the
elements, aligned and in the same column so that it is easy to see one
is not missing, you also don’t need to maintain the commas at the end
of the line.

But you don’t have a comma before the first element.

On Dec 12, 6:26 pm, ry dahl [email protected] wrote:

p h

C:>ruby tmp.rb
{:c=>3, :a=>1, :b=>2}
No, the benefit is that the separators are at the beginning of the
elements, aligned and in the same column so that it is easy to see one
is not missing, you also don’t need to maintain the commas at the end
of the line.

Ah; I thought the ‘obvious’ benefit you were referring to was that you
could copy/paste lines to change the order without having to remember
to use commas after every element except the last.

On Dec 13, 11:24 am, Phrogz [email protected] wrote:

:b => 2,
of the line.

Ah; I thought the ‘obvious’ benefit you were referring to was that you
could copy/paste lines to change the order without having to remember
to use commas after every element except the last.

In haskell (mainly because of “layout”) and to a lesser extent, ocaml,
people tend to format records (and such) with a syntax that commas
line up with the opening/closing bracket, and appear on the line after
the record field declaration. It makes kind of a visual “wall” between
the name binding and the body of the declaration. It’s just a matter
of taste and custom, and really, even with haskell, some people format
their code differently.

Regards,
Jordan

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs