scala

How large can a Java BigInteger be? alvin January 19, 2019 - 12:08pm

Java FAQ: How large can a Java BigInteger be?

Answer: The Java BigInteger Scaladoc states the following:

“BigInteger must support values in the range -2Integer.MAX_VALUE (exclusive) to +2Integer.MAX_VALUE (exclusive) and may support values outside of that range.”

The Scala BigInt wraps Java’s BigInteger, so it will also have the same data range.

The `f` string interpolator does not work with Dotty (Scala 3)

If you happen to be using Dotty (Scala 3) and find that the f string interpolator isn’t working, it’s a known bug. (It was implemented with a macro, and the old, experimental macro system has been dropped.) I’m writing this in January, 2019; I don’t know when it will work again. You can use the Java/Scala String.format method until it’s fixed:

val pi = scala.math.Pi
println( "%1.5f".format(pi) )

What types are special to the Scala compiler or runtime?

From the URL:

Q: Scala makes a big deal about how what seem to be language features are implemented as library features. Is there a list of types that are treated specially by the language?

A: The following types are crucial to Scala's type system. They have an influence on how type checking itself is performed.

It’s interesting that you can do some research on this by looking at Definitions.scala.

A note about Scala/Java startup time

I was reading this post by Martin Odersky (Make the Scala runtime independent of the standard library) and came across this comment by Li Haoyi: “This would also make it more feasible to use Scala for tiny bootstrap scripts; current Mill’s launcher is written in Java because the added classloading needed to use scala.Predef (even just println) easily adds a 200-400ms of initialization overhead.” I haven’t written anything where the startup time of a Scala application was a huge problem, but that was interesting to read.

(Though I should say that I wish all Scala/Java command-line apps started faster. It’s one reason I occasionally think about using Haskell for small scripts, so I can compile them to an executable.)

Scala SBT scalacOptions syntax/examples

As a quick note to self, here’s an example of how to set scalacOptions in an SBT build.sbt file:

scalacOptions ++= Seq(
    "-Xfatal-warnings",
    "-deprecation",
    "-feature",
    "-unchecked",
    "-language:implicitConversions",
    "-language:higherKinds",
    "-language:existentials",
    "-language:postfixOps"
)

As shown, scalacOptions lets you set Scala compiler options in your SBT project build.