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

Why no mutable "List"?

6 replies
Russ P.
Joined: 2009-01-31,
User offline. Last seen 1 year 26 weeks ago.
Scala has both a mutable and an immutable "Map", but it has only an immutable "List." If you want a mutable "List," you need a "ListBuffer." Am I missing something, or is that a slight inconsistency?

Russ P.

Randall R Schulz
Joined: 2008-12-16,
User offline. Last seen 1 year 29 weeks ago.
Re: Why no mutable "List"?

On Friday March 19 2010, Russ Paielli wrote:
> Scala has both a mutable and an immutable "Map", ...

And Set.

> ... but it has only an immutable "List."
> If you want a mutable "List," you need a "ListBuffer." ...

ListBuffer is the mutable List.

List is special thing. It is in its very essence immutable.
(Pay no attention to Common Lisp and it's heinous cons cell mutators.)

> Russ P.

Randall Schulz

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Why no mutable "List"?
More to the point, Seq, Map and Set are abstract classes. List is an implementation of a Seq, as is ListBuffer.

On Fri, Mar 19, 2010 at 10:52 PM, Randall R Schulz <rschulz@sonic.net> wrote:
On Friday March 19 2010, Russ Paielli wrote:
> Scala has both a mutable and an immutable "Map", ...

And Set.

> ... but it has only an immutable "List."
> If you want a mutable "List," you need a "ListBuffer." ...

ListBuffer is the mutable List.

List is special thing. It is in its very essence immutable.
(Pay no attention to Common Lisp and it's heinous cons cell mutators.)


> Russ P.


Randall Schulz



--
Daniel C. Sobral

I travel to the future all the time.
Russ P.
Joined: 2009-01-31,
User offline. Last seen 1 year 26 weeks ago.
Re: Why no mutable "List"?
On Fri, Mar 19, 2010 at 11:21 PM, Daniel Sobral <dcsobral@gmail.com> wrote:
More to the point, Seq, Map and Set are abstract classes. List is an implementation of a Seq, as is ListBuffer.

I think List is an abstract class too:
sealed abstract class List[+A]
extends Seq[A] with Product


On Fri, Mar 19, 2010 at 10:52 PM, Randall R Schulz <rschulz@sonic.net> wrote:
On Friday March 19 2010, Russ Paielli wrote:
> Scala has both a mutable and an immutable "Map", ...

And Set.

> ... but it has only an immutable "List."
> If you want a mutable "List," you need a "ListBuffer." ...

ListBuffer is the mutable List.

List is special thing. It is in its very essence immutable.
(Pay no attention to Common Lisp and it's heinous cons cell mutators.)


> Russ P.


Randall Schulz



--
Daniel C. Sobral

I travel to the future all the time.



--
http://RussP.us
dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Why no mutable "List"?
Ah, well, true enough. But that's a minor construction detail -- as one can see by the "sealed". That means the only classes extending List are defined in the same file. List is effectively a specific implementation of an immutable Seq, which happens to be defined through the concrete classes Cons and Nil.

On Sat, Mar 20, 2010 at 2:53 PM, Russ Paielli <russ.paielli@gmail.com> wrote:
On Fri, Mar 19, 2010 at 11:21 PM, Daniel Sobral <dcsobral@gmail.com> wrote:
More to the point, Seq, Map and Set are abstract classes. List is an implementation of a Seq, as is ListBuffer.

I think List is an abstract class too:
sealed abstract class List[+A]
extends Seq[A] with Product


On Fri, Mar 19, 2010 at 10:52 PM, Randall R Schulz <rschulz@sonic.net> wrote:
On Friday March 19 2010, Russ Paielli wrote:
> Scala has both a mutable and an immutable "Map", ...

And Set.

> ... but it has only an immutable "List."
> If you want a mutable "List," you need a "ListBuffer." ...

ListBuffer is the mutable List.

List is special thing. It is in its very essence immutable.
(Pay no attention to Common Lisp and it's heinous cons cell mutators.)


> Russ P.


Randall Schulz



--
Daniel C. Sobral

I travel to the future all the time.



--
http://RussP.us



--
Daniel C. Sobral

I travel to the future all the time.
richard emberson
Joined: 2010-03-22,
User offline. Last seen 42 years 45 weeks ago.
Hardest bug so far (newbie)

def buf = new StringBuilder(64);
....
buf.append(someString)
...
System.out.println(buf.toString)

Finding this in 100 lines of code took a while

Richard

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Hardest bug so far (newbie)
I have had def sneak up on me. Finding it in a dozen lines is difficult as well...

On Sun, Mar 21, 2010 at 10:27 PM, richard emberson <richard.emberson@gmail.com> wrote:
def buf = new StringBuilder(64);
....
buf.append(someString)
...
System.out.println(buf.toString)

Finding this in 100 lines of code took a while

Richard

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