compile

How curried functions and partially-applied functions compile in Scala

Table of Contents1 - A curried function test class2 - Result: The bytecode is the same3 - Be careful looking at -Xprint output4 - Final decompiled source code5 - scalac Xprint parser phases6 - Summary

This morning I was curious about how Scala curried functions and partially-applied functions are really compiled at a bytecode level.

Prior to that, I wrote this post that Higher order functions are the Haskell experience — which is also implicitly about curried functions — and it got me thinking about Scala, in particular why we might use one function syntax versus another, i.e., why would I use this syntax:

 

(this space left blank for the ToC over there --> )
 

How to compile, run, and package a Scala project with SBT

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 18.2, “How to compile, run, and package a Scala project with SBT.”

Back to top

Problem

You want to use SBT to compile and run a Scala project, and package the project as a JAR file.

Back to top

Solution

Create a directory layout to match what SBT expects, then run sbt compile to compile your project, sbt run to run your project, and sbt package to package your project as a JAR file.

Table of Contents

  1. Problem
  2. Solution
Back to top
How to make your Scala shell scripts run faster by pre-compiling them alvin June 20, 2015 - 4:39pm

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is a short recipe, Recipe 14.13, “How to make your Scala shell scripts run faster by pre-compiling them.”

Problem

You love using Scala as a scripting language, but you’d like to eliminate the lag time in starting up a script.

Solution

Use the -savecompiled argument of the Scala interpreter to save a compiled version of your script.

A basic Scala script like this:

How to compile Scala code faster with the 'fsc' command-line compiler

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is a short recipe, Recipe 14.9, “How to compile your Scala code faster with the 'fsc' command-line compiler.”

Problem

You’re making changes to a project and recompiling it with scalac, and you’d like to reduce the compile time.

Solution

Use the fsc command instead of scalac to compile your code:

How to compile Scala code with ‘scalac’ and run it with ‘scala’

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 14.5, “How to compile Scala code with 'scalac' and run it with 'scala'.”

Problem

Though you normally use the Simple Build Tool (SBT) to build Scala applications, you may want to use more basic tools to compile and run small test programs, in the same way you might use javac and java with small Java applications.

Common SBT commands (Scala SBT)

I had the common Scala SBT commands in the notes for my project named SARAH, and thought I'd list them here to make them easier to find:

A Java regular expression example (featuring Pattern and Matcher classes)

Summary: Java regular expressions in Java 1.4, featuring regex expressions and pattern matching, using the new Java Pattern and Matcher classes.

The following Java example offers an introduction to regular expressions in Java 1.4. In this code we're creating a regular expression that can search for a date. Specifically, that date must be in a format of two digits, followed by a hyphen, followed by two digits, followed by a hyphen, followed by four digits.

This date pattern is created in this line of code: