Using the Scala REPL as a makeshift Java REPL

Image for post
Image for post
A little bit of a run of the Scala REPL with one of my Java JARs loaded in.
    @Test
public void testEuclideanGCDWithFibonacciNumbers() {
int fibo1 = 0;
int fibo2 = 1;
int fiboSum;
while (fibo2 < Integer.MAX_VALUE/8) {
fiboSum = fibo1 + fibo2;
fibo1 = fibo2;
fibo2 = fiboSum;
assertEquals(1, euclideanGCD(fibo1, fibo2));
}
}
Welcome to Scala 2.12.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_161).Type in expressions for evaluation. Or try :help.
scala> 1 + 1
res0: Int = 2
scala> 3.getClass
res1: Class[Int] = int
scala> val ringZi2 = new imaginaryquadraticinteger.ImaginaryQuadraticRing(-2)ringZi2: imaginaryquadraticinteger.ImaginaryQuadraticRing = Z[?-2]
  def +(summand: ImagQuadInt): ImagQuadInt = {
val temp = this.plus(summand)
new ImagQuadInt(temp.realPartMult, temp.imagPartMult,
temp.imagQuadRing, temp.denominator)
}
scala> var numberC = numberA * numberBnumberC: imaginaryquadraticinteger.ImagQuadInt = 5 + sqrt(-2)
scala> imaginaryquadraticinteger.NumberTheoreticFunctionsCalculator.isPrime(numberC)res7: Boolean = false
scala> try { numberC/numberA } catch { case nde: imaginaryquadraticinteger.NotDivisibleException => notDivExc = nde }
res42: Any = ()
scala> notDivExc
res43: imaginaryquadraticinteger.NotDivisibleException = imaginaryquadraticinteger.NotDivisibleException: -16 + 19sqrt(-2) is not divisible by 4 + 2sqrt(-2).
scala> notDivExc.roundTowardsZero
res45: imaginaryquadraticinteger.ImaginaryQuadraticInteger = 4?(-2)
scala> notDivExc.getBoundingIntegers
res46: Array[imaginaryquadraticinteger.ImaginaryQuadraticInteger] = Array(4?(-2), 1 + 4?(-2), 5?(-2), 1 + 5?(-2))

is a composer and photographer from Detroit, Michigan. He has been working on a Java program to display certain mathematical diagrams.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store