# scala 3

A Scala function to determine whether a number is a prime number alvin February 3, 2020 - 3:52pm

Not having a computer science background, I was curious about how to write a Scala function that would find a list of all prime numbers up until some maximum value I supply. I was aware of the Sieve of Eratosthenes, but I didn’t want to implement that, at least not today.

## A Scala 3 (Dotty) function

What I ended up doing looks like other Scala prime number solutions you can find on the internet. To make things look a little different, I wrote the code using the current Scala 3 (Dotty) syntax, and the result looks like this:

def isPrime(i: Int): Boolean =
if (i <= 1)
false
else if (i == 2)
true
else
!(2 until i).exists(n => i % n == 0)
Scala 3: The Dotty if/then/else-if/else/end syntax alvin January 27, 2020 - 11:45am

Table of Contents1 - Using `then` with if/else2 - Using `end if` with if/else3 - Closing a function with `end`4 - Discussion5 - Participate/contribute!6 - Attribution

As a brief note today, here’s an example of the Scala 3 “Dotty” if/then/else-if/else syntax, as used in a function:

def compare(a: Int, b: Int): Int =
if a < b
-1
else if a == b
0
else
1

## Using `then` with if/else

You can also use the then keyword after your if expressions, if you prefer:

A small Scala 2 project converted to Dotty alvin January 20, 2020 - 3:40pm

If you want to see a somewhat larger example of Dotty source code than I’ve shown before, I just took a little time to convert a small Scala 2 project over to the new/current Dotty syntax (i.e., the Dotty syntax supported by the Dotty 0.21 release, circa January, 2020).

Scala 2.13’s ‘pipe’ and ‘tap’ chaining operations alvin January 12, 2020 - 5:08pm

Scala 2.13 introduced two new “chaining operations” named pipe and tap. Here’s a quick look at how they work, plus a little extra fun at the end.

Notes on using Dotty (Scala 3), SBT, and VS Code together alvin December 3, 2019 - 5:28pm

As a note to self, here are some ways to work with Dotty (Scala 3), SBT, and VS Code (Visual Studio Code).

Create a Dotty project:

sbt new lampepfl/dotty.g8

Launch VS Code inside that project directory, with Dotty support:

sbt launchIDE

Start SBT as usual:

sbt

Those notes are just a reminder for myself, but hopefully they’ll also help others work with Dotty, SBT, and VS Code.

A quiet, attractive new programming language (Scala 3) alvin November 25, 2019 - 7:53am

Here’s some source code that demonstrates a quiet, concise, and attractive new programming language I’d enjoy using:

Examples of converting Scala 2 code to Scala 3 with Dotty 0.20 alvin November 10, 2019 - 5:58pm