comma separated lists syntax error

R

ry dahl

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
 
P

Phrogz

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.

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}
 
A

Andrei Maxim

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
}

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.
 
R

ry dahl

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.
 
T

Tim Hunter

Andrei said:
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.
 
N

Nobuyoshi Nakada

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.
 
P

Phrogz

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.
 
M

MonkeeSage

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,274
Messages
2,571,366
Members
48,051
Latest member
noblesalt

Latest Threads

Top