This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Why does Tuple1.toString add a trailing comma?

2 replies
Dean Wampler
Joined: 2008-12-26,
User offline. Last seen 42 years 45 weeks ago.
I noticed the following today:
scala> Tuple1("foo")         res55: (java.lang.String,) = (foo,)
Why is there a trailing "," added? This appears to be deliberate: http://lampsvn.epfl.ch/trac/scala/changeset/9507
It's true for 2.7.X and 2.8. None of the other Tuples do this.
If this is actually a bug, I'll file a trac bug.
Thanks,Dean
Matt Fowles
Joined: 2009-07-09,
User offline. Last seen 42 years 45 weeks ago.
Re: Why does Tuple1.toString add a trailing comma?

Dean~

This is probably to avoid ambiguity between 1 element tuples and parens used for precedence grouping. (1+2) is 3 while (1+2,) is list(3).  Python does the same thing.

Matt

On Aug 8, 2009 5:36 PM, "Dean Wampler" <deanwampler@gmail.com> wrote:

I noticed the following today:
scala> Tuple1("foo")          res55: (java.lang.String,) = (foo,)
Why is there a trailing "," added? This appears to be deliberate: http://lampsvn.epfl.ch/trac/scala/changeset/9507
It's true for 2.7.X and 2.8. None of the other Tuples do this.
If this is actually a bug, I'll file a trac bug.
Thanks,Dean

Dean Wampler
Joined: 2008-12-26,
User offline. Last seen 42 years 45 weeks ago.
Re: Why does Tuple1.toString add a trailing comma?
Ah, that would make sense, if inconvenient at times ;) Thx.
dean

On Sat, Aug 8, 2009 at 4:42 PM, Matt Fowles <matt.fowles@gmail.com> wrote:

Dean~

This is probably to avoid ambiguity between 1 element tuples and parens used for precedence grouping. (1+2) is 3 while (1+2,) is list(3).  Python does the same thing.

Matt

On Aug 8, 2009 5:36 PM, "Dean Wampler" <deanwampler@gmail.com> wrote:

I noticed the following today:
scala> Tuple1("foo")          res55: (java.lang.String,) = (foo,)
Why is there a trailing "," added? This appears to be deliberate: http://lampsvn.epfl.ch/trac/scala/changeset/9507
It's true for 2.7.X and 2.8. None of the other Tuples do this.
If this is actually a bug, I'll file a trac bug.
Thanks,Dean

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland