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
|
|
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.
|
|