Forays Into AI

The only way to discover the limits of the possible is to go beyond them into the impossible. - Arthur C. Clarke

Setting Up Scala on Ubuntu

Scala is a powerful and versatile programming language that combines object-oriented and functional programming paradigms. It is designed to be concise and expressive, enabling developers to write robust and high-performance code. In this tutorial, we will guide you through setting up Scala 3 on an Ubuntu system using SDKMAN! to manage the JDK and Coursier (cs) to install Scala. Follow these steps to get your environment ready for Scala development.

Prerequisites

Before you begin, make sure you have:

  • An Ubuntu system (18.04 or later)
  • sudo access to install packages

Step 1: Install SDKMAN!

SDKMAN! is a tool for managing parallel versions of multiple software development kits on most Unix-based systems.

  1. Open a terminal window.

  2. Install SDKMAN!:

    curl -s "https://get.sdkman.io" | bash
    
  3. Follow the instructions displayed on the terminal to finalize the installation. This typically involves running:

    source "$HOME/.sdkman/bin/sdkman-init.sh"
    
  4. Verify the installation:

    sdk version
    

    You should see the version of SDKMAN! installed.

Step 2: Install JDK 21 using SDKMAN!

  1. Use SDKMAN! to install JDK 21:

    sdk install java 21.0.2-open
    

    Or you can check for candidate versions by running:

    sdk list java
    
  2. Verify the installation:

    java -version
    

    You should see output similar to:

    java -version
    openjdk version "21.0.2" 2024-01-16
    OpenJDK Runtime Environment (build 21.0.2+13-58)
    OpenJDK 64-Bit Server VM (build 21.0.2+13-58, mixed mode, sharing)
    

Step 3: Install Coursier and Scala (cs)

Coursier is a tool that simplifies the installation of Scala and related tools.

curl -fL https://github.com/coursier/coursier/releases/latest/download/cs-x86_64-pc-linux.gz |  gzip -d > cs \
&& chmod +x cs \
&& ./cs setup

This installs Scala 3 by default, though projects can still use different versions of Scala depending on build settings - see Getting Started.

Note that Coursier can also manage the JVM installation.

cs java --jvm 21 --version

should output something like:

openjdk 21.0.3 2024-04-16 LTS
OpenJDK Runtime Environment Temurin-21.0.3+9 (build 21.0.3+9-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.3+9 (build 21.0.3+9-LTS, mixed mode, sharing)

Step 4: Set Up Your Development Environment

  1. Ensure that your PATH includes the directory where Coursier installs executables. Typically, this is ~/.local/share/coursier/bin. You can add this to your .bashrc or .zshrc file:

    echo 'export PATH="$PATH:$HOME/.local/share/coursier/bin"' >> ~/.bashrc
    source ~/.bashrc
    
  2. Test your setup using the scala cli: Launch the Scala CLI using:

cs launch scala3

You should output similar to:

Welcome to Scala 3.4.2 (17.0.1, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                              
scala> 

Now you can try Scala commands e.g.:

scala> 1 + 1

with output

val res0: Int = 2

Conclusion

You have successfully set up Scala 3 on your Ubuntu system using SDKMAN! for managing JDK 21 and Coursier for installing Scala. You can now start developing Scala applications on your machine. Happy coding!

TaggedScalaSDKMAN!UbuntuJDK 21

Enumerations in Scala 2 vs Scala 3

In the ever-evolving world of programming languages, Scala 3 has made substantial improvements in the implementation of enumerations. This blog post will look into the differences between Scala 2 and Scala 3 enumerations, highlighting the enhancements and providing practical insights for developers.

Python Decorators: Enhance Your Code with Function Wrappers

Ever wished you could enhance your Python functions without modifying their core logic? This tutorial introduces decorators - a powerful feature that allows you to modify or extend the behavior of functions and classes with just a simple @ symbol.

Lazy Evaluation with Python Generators

Have you ever worked with large datasets in Python and found your program grinding to a halt due to memory constraints. This tutorial discusses lazy evaluation using Python generators.

Introduction to Lambda Functions

Lambda functions are a powerful tool for writing efficient Python code when used appropriately. This tutorial provides an overview of lambda functions in Python, covering the basic syntax, demonstrating how these anonymous functions are defined using the lambda keyword.