# Comma separated lists syntax error

**URL:** <https://www.ruby-forum.com/t/comma-separated-lists-syntax-error/122962>\
**Category:** Ruby\
**Created:** [December 13, 2007, 1:13am UTC](https://www.ruby-forum.com/t/comma-separated-lists-syntax-error/122962 "2007-12-13T01:13:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 13, 2007, 1:13am UTC](https://www.ruby-forum.com/t/comma-separated-lists-syntax-error/122962/1 "2007-12-13T01:13:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 13, 2007, 1:35am UTC](https://www.ruby-forum.com/t/comma-separated-lists-syntax-error/122962/2 "2007-12-13T01:35:48Z")

</div>

On Dec 12, 5:11 pm, ry dahl [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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}

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 13, 2007, 2:26am UTC](https://www.ruby-forum.com/t/comma-separated-lists-syntax-error/122962/3 "2007-12-13T02:26:42Z")

</div>

On 12/13/07, ry dahl [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 13, 2007, 2:27am UTC](https://www.ruby-forum.com/t/comma-separated-lists-syntax-error/122962/4 "2007-12-13T02:27:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 13, 2007, 3:01am UTC](https://www.ruby-forum.com/t/comma-separated-lists-syntax-error/122962/5 "2007-12-13T03:01:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 13, 2007, 5:24am UTC](https://www.ruby-forum.com/t/comma-separated-lists-syntax-error/122962/6 "2007-12-13T05:24:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 13, 2007, 6:47pm UTC](https://www.ruby-forum.com/t/comma-separated-lists-syntax-error/122962/7 "2007-12-13T18:47:21Z")

</div>

On Dec 12, 6:26 pm, ry dahl [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 14, 2007, 8:10pm UTC](https://www.ruby-forum.com/t/comma-separated-lists-syntax-error/122962/8 "2007-12-14T20:10:56Z")

</div>

On Dec 13, 11:24 am, Phrogz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
