開発環境
- OS X Yosemite - Apple (OS)
- Emacs (Text Editor)
- Scala (プログラミング言語)
Learning Scala: Practical Functional Programming for the JVM (Jason Swartz (著)、O'Reilly Media)のPart Ⅰ. (Core Scala)、Chapter 4.(Functions)、Exercises 2.(No. 1471)を解いてみる。
その他参考書籍
Exercises 2.(No. 1471)
コード(Emacs)
def areaOrCircle(radius: String): Double = {
val r = radius.toDouble
r * r * 3.14
}
println(areaOrCircle("1"))
println(areaOrCircle("10"))
println(areaOrCircle("")) // error
入出力結果(Terminal, REPL(Read, Eval, Print, Loop))
$ scala-2.11 sample2.scala 3.14 314.0 java.lang.NumberFormatException: empty String at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1842) at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110) at java.lang.Double.parseDouble(Double.java:538) at scala.collection.immutable.StringLike$class.toDouble(StringLike.scala:284) at scala.collection.immutable.StringOps.toDouble(StringOps.scala:30) at Main$$anon$1.areaOrCircle(sample2.scala:2) at Main$$anon$1.<init>(sample2.scala:8) at Main$.main(sample2.scala:1) at Main.main(sample2.scala) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at scala.reflect.internal.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:70) at scala.reflect.internal.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:31) at scala.reflect.internal.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:101) at scala.reflect.internal.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:70) at scala.reflect.internal.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:101) at scala.tools.nsc.CommonRunner$class.run(ObjectRunner.scala:22) at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:39) at scala.tools.nsc.CommonRunner$class.runAndCatch(ObjectRunner.scala:29) at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:39) at scala.tools.nsc.ScriptRunner.scala$tools$nsc$ScriptRunner$$runCompiled(ScriptRunner.scala:175) at scala.tools.nsc.ScriptRunner$$anonfun$runScript$1.apply(ScriptRunner.scala:192) at scala.tools.nsc.ScriptRunner$$anonfun$runScript$1.apply(ScriptRunner.scala:192) at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1$$anonfun$apply$mcZ$sp$1.apply(ScriptRunner.scala:161) at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1.apply$mcZ$sp(ScriptRunner.scala:161) at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1.apply(ScriptRunner.scala:129) at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1.apply(ScriptRunner.scala:129) at scala.tools.nsc.util.package$.trackingThreads(package.scala:43) at scala.tools.nsc.util.package$.waitingForThreads(package.scala:27) at scala.tools.nsc.ScriptRunner.withCompiledScript(ScriptRunner.scala:128) at scala.tools.nsc.ScriptRunner.runScript(ScriptRunner.scala:192) at scala.tools.nsc.ScriptRunner.runScriptAndCatch(ScriptRunner.scala:205) at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:67) at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:87) at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:98) at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:103) at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala) $
0 コメント:
コメントを投稿