The Artima Developer Community
Sponsored Link

Programming in Scala Forum
Unable to Run Scala code on pg104 in the e-book edition

1 reply on 1 page. Most recent reply: Dec 21, 2014 3:31 PM by Tris Nefzger

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 1 reply on 1 page
Samwel Kiprono

Posts: 1
Nickname: kiprono
Registered: Aug, 2014

Unable to Run Scala code on pg104 in the e-book edition Posted: Aug 21, 2014 6:31 AM
Reply to this message Reply
Advertisement
Scala error while running a program in command prompt
i.e c:\scala sripts>scala Summer$$anonfun$main$1.class
the error below is displayed
No such file or class on classpath:Summer.class


kindly assist


Tris Nefzger

Posts: 6
Nickname: alacer
Registered: Dec, 2014

Re: Unable to Run Scala code on pg104 in the e-book edition Posted: Dec 21, 2014 3:31 PM
Reply to this message Reply
I coudn't run the Summer application in REPL and instead compiled Summer.scala and ChecksumAccumulator.scala and then ran "Summer of love" on the command line as shown in the book. When I ran it I did so in a Windows cmd.exe session with current directory the same as that where the compilations were done and this was the classes-and-objects folder in the source code download for the book. Below is a transcript of the session:

$ dir
Volume in drive C is OS
Volume Serial Number is 5B75-665D

Directory of C:\Users\tn\Documents\scala\progInScalaExamples2Ed\classes-and-objects

12/02/2 014 11:26 PM <DIR> .
12/02/2014 11:26 PM <DIR> ..
12/12/2010 08:39 PM 1,358 ChecksumAccumulator.scala
12/12/2010 08:39 PM 996 ChecksumCalculator1.scala
12/12/2010 08:39 PM 1,156 ChecksumCalculator2.scala
12/12/2010 08:39 PM 1,112 ChecksumCalculator3.scala
12/12/2010 08:39 PM 1,147 ChecksumCalculator4.scala
12/12/2010 08:39 PM 988 FallWinterSpringSummer.scala
12/12/2010 08:39 PM 1,209 SemiInference.scala
12/12/2010 08:39 PM 961 Summer.scala
12/10/2010 01:08 PM 2,447 transcript.txt
9 File(s) 11,374 bytes
2 Dir(s) 330,764,578,816 bytes free

$ scalac ChecksumAccumulator.scala

$ scalac Summer.scala

$ dir
Volume in drive C is OS
Volume Serial Number is 5B75-665D

Directory of C:\Users\tn\Documents\scala\progInScalaExamples2Ed\classes-and-objects

12/21/2 014 06:05 PM <DIR> .
12/21/2014 06:05 PM <DIR> ..
12/21/2014 06:05 PM 1,239 ChecksumAccumulator$$anonfun$calculate$1.class
12/21/2014 06:05 PM 2,273 ChecksumAccumulator$.class
12/21/2014 06:05 PM 1,542 ChecksumAccumulator.class
12/12/2010 08:39 PM 1,358 ChecksumAccumulator.scala
12/12/2010 08:39 PM 996 ChecksumCalculator1.scala
12/12/2010 08:39 PM 1,156 ChecksumCalculator2.scala
12/12/2010 08:39 PM 1,112 ChecksumCalculator3.scala
12/12/2010 08:39 PM 1,147 ChecksumCalculator4.scala
12/12/2010 08:39 PM 988 FallWinterSpringSummer.scala
12/12/2010 08:39 PM 1,209 SemiInference.scala
12/21/2014 06:05 PM 1,513 Summer$$anonfun$main$1.class
12/21/2014 06:05 PM 792 Summer$.class
12/21/2014 06:05 PM 620 Summer.class
12/12/2010 08:39 PM 961 Summer.scala
12/10/2010 01:08 PM 2,447 transcript.txt
15 File(s) 19,353 bytes
2 Dir(s) 330,764,484,608 bytes free

$ scala Summer of love
of: -213
love: -182

$


A tip for entering a class definition and its companion object definiton in REPL is to enter paste mode with the :paste command, then paste in both of them and hit <CTRL>D to exit paste mode.

For all the code examples that I have run, after compilation I put the all the compiled classes in a separate folder called "class" and put the pathname of this folder in the value of the CLASSPATH environment variable. Also I compiled all classes after removing any package declarations they may have contained to keep it simple under the assumption there would be no name conflicts which has worked up to chapter 28 so far. This simplifies running all the programs since none of them require an import first or prefixing their class names with a package name.

Flat View: This topic has 1 reply on 1 page
Topic: In search of deeper understanding of higher-function Previous Topic   Next Topic Topic: scala.Application??

Sponsored Links



Google
  Web Artima.com   

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