Scastie now makes it even easier to save Scala snippets

Photo by Micheile Henderson on Unsplash

A couple of months ago, I wrote about how Scastie, an online REPL for Scala, makes it easy to get started learning Scala.

Any time you write about computers, even if everything is correct at the time you published, you run the risk that some or all of what you wrote will become outdated soon after publication.

That is the case with my article about Scastie. Most of it is still correct, and my post-publication edits have been to clarify certain details, not to update anything. But some things do need to be updated.

I’m still not ready to say that Scastie won’t work on Internet Explorer or Edge, though I doubt anyone is sweating this. I can now say that Scastie does work on Mac OS X Safari. And of course it still works on any up-to-date version of Chrome, Firefox or Opera.

It looks like the “Hello world” example for first-time users has been dropped. Now first-time users get a blank editor area (which you can verify by using a different browser or computer).

Much more important are the changes to the “Run” button, which still has a play button for an icon, but is now called “Save.”

Let’s say that you’ve just typed in a Scala snippet like this one:

Then you click “Save.” Notice that now Scastie adds to its own URL in the Web browser’s address bar a seemingly random sequence of letters and digits, such as QzqTVceFTiuFAi6CcuCB8g.

Then that new URL is an URL that you can use to tell others to look at your Scala snippet, or to go back to it yourself. In fact, the snippet quoted above is at this URL:

If it’s valid Scala, you might see the output at the end. In this case, that would be the result of gcd(−27, 18) using the Euclidean algorithm with the squaring function as the Euclidean function, which in this case is 9 as a 64-bit integer.

You can change the last line to instead use negCube(), invalidFunctionF() or some new function that you write in there. The first two of these should cause runtime exceptions, your own function may or may not.

Notice also that now Scastie will show the exception message and stack trace right under the line that caused it, rather than in the console.

You may also make more radical changes to the snippet, including deleting it altogether and starting a completely new snippet (though then it would probably be better to just click “New”). Then those should get saved with new URLs.

I prepared two other snippets to use for examples: one snippet is for negative Fibonacci numbers requiring more than 64 bits, the other snippet is for the infamous FizzBuzz, also demonstrated with negative numbers.

If you come up with interesting modifications to these snippets, or any other snippets you’d like me to take a look at, please post them in comments below.

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

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