The Artima Developer Community
Sponsored Link

Programming in Scala Forum
Naive Question

4 replies on 1 page. Most recent reply: Nov 23, 2008 7:04 PM by Vladimir Kelman

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Ian Coleman

Posts: 3
Nickname: 56491
Registered: Jun, 2008

Naive Question Posted: Jun 24, 2008 9:39 AM
Reply to this message Reply
Advertisement
I ran the first example through the Scala intepreter (please don't laugh):


#!/usr/bin/env scala
!#

var capital = Map("US" -> "Washington", "Japan" -> "Tokyo")
capital += ("France", "Paris")
println(capital("France"))


The text says, "The notation in this example is
high-level, to the point, and not cluttered with extraneous semicolons or type annotations." And I agree. But it also fails to run. :)

I'm assuming this is *not* valid Scala code?


Ian Coleman

Posts: 3
Nickname: 56491
Registered: Jun, 2008

Re: Naive Question Posted: Jun 24, 2008 9:40 AM
Reply to this message Reply
Sorry, error message would be helpful:


(fragment of fpa.scala):3: error: value += is not a member of scala.collection.immutable.Map[java.lang.String,java.lang.
String]
capital += ("France", "Paris")
^
one error found
!!!
discarding <script preamble>

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: Naive Question Posted: Jun 24, 2008 2:13 PM
Reply to this message Reply
Hi Ian,

I think you mistyped the second line from the book. It should be:

capital += ("Japan" -> "Tokyo")

You have a comma where the -> should be.

Ian Coleman

Posts: 3
Nickname: 56491
Registered: Jun, 2008

Re: Naive Question Posted: Jun 24, 2008 2:28 PM
Reply to this message Reply
You have a comma where the -> should be.

Thanks, Bill. I knew it was something stupid.

It's funny, I'm really at square one here. I feel like I'm just transcribing hieroglyphs... ;)

--ian

Vladimir Kelman

Posts: 46
Nickname: vkelman
Registered: Feb, 2008

Re: Naive Question Posted: Nov 23, 2008 7:04 PM
Reply to this message Reply
By the way, Ian, you could write
capital += (("France", "Paris"))
and it would work as well, although this syntax is less obvious. A "Map.+=()" requires a tuple as parameter. This tuple could be created as "France" => "Paris" or as ("France", "Paris"). These two forms are equivalent, if I'm not mistaken.

Flat View: This topic has 4 replies on 1 page
Topic: Ch2:Step5 pre-post increment operators Previous Topic   Next Topic Topic: Final version is...?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use