Simply Scala

Version of implementation Simply Scala of programming language Scala

Simply Scala has only one version that works online and is updated to process new versions of Scala when they are available. Older versions are not available.

Examples:

Hello, World! - Scala (196):

In Simply Scala you can evaluate expressions without framing them as objects.

println("Hello, World!")

Factorial - Scala (197):

This examples shows how to define ! as a method applied to Int.

def factorial(n: Int): BigInt = 
    if (n == 0) 1 
           else factorial(n - 1) * n
class Factorizer(n: Int) {
    def ! = factorial(n)
}
implicit def int2fact(n: Int) = new Factorizer(n);	

for {i <- List.range(0, 17)} 
    println(i + "! = " + (i!))

Fibonacci numbers - Scala (145):

This example shows the usage of lazy evaluations and infinite lists in Scala. Infinite list of Fibonacci numbers is defined using functions .zip and .tail in the same way as in Haskell example.

lazy val fib: Stream[Int] = Stream.cons(1, Stream.cons(1, fib.zip(fib.tail).map(p => p._1 + p._2)))
fib.take(16).print

Quadratic equation - Scala (198):

This example shows that string processing and Math in Scala are implemented similarly to Java.

def output(real: Double, imag: Double): String = 
    if (imag == 0) ""+real
              else "("+real+","+imag+")"

def solve(A: Int, B: Int, C: Int)
{   if (A == 0) print("Not a quadratic equation.")
    else
    {   def D = B*B - 4*A*C
        if (D == 0) print("x = "+output(-B/2.0/A, 0))
        else if (D > 0) print("x1 = "+output((-B+Math.sqrt(D))/2.0/A, 0)+"\nx2 = "+output((-B-Math.sqrt(D))/2.0/A, 0))
             else print("x1 = "+output(-B/2/A, Math.sqrt(-D)/2.0/A)+"\nx2 = "+output(-B/2/A, -Math.sqrt(-D)/2.0/A))
    }
}