Programming Languages Section

Clojure

Card image
Post by Amina Delali, November 29th,2021

Some Facts

Clojure is a dialect of the Lisp programming language. Clojure is dynamic, compiled , and a general-purpose functional language. It is also a scripting language with an infrastructure for multi-thread programming. The language is modular and reusable, and was used by different companies like Walmart, Chartbeat, and 8th Light



How to install it

  • on Windows:

    First of all, the Java programming language must be already installed on your system. You also have to set the JAVA_HOME variable. Then, do the following:

    1. Open PowerShell and write the following command: Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
    2.  Now type in the following command: Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://download.clojure.org/install/win-install-1.10.3.1029.ps1')
    3. The previous command will download and run the installer. When it is running, you will be prompted to select the location of the installation. You can type 1 to select the first option. 
    4. You can check your installation using PowerShell  and the following command: clj

  • on ubuntu :

    As for Windows 10, you must have Java already installed on your system. And have either the JAVA_HOME variable set, or have the java command in your path. Then open the terminal, and  : 

    1. Run the following command: sudo apt update

    2. Install the dependencies.
      • To Install Java, you can follow the instructions available in this post.
      • Install curl using this command: . sudo apt install curl
      • You can also install rlwrap by the following command: sudo apt install rlwrap

    3. To download and run the installer, run the following commands: curl -O https://download.clojure.org/install/linux-install-1.10.3.1029.sh
      chmod +x linux-install-1.10.3.1029.sh 
      sudo ./linux-install-1.10.3.1029.sh

    4. To check your installation, just run this command: clj --version

    5. You can delete the linux-install file after the installation was successful: rm linux-install-1.10.3.1029.sh

     

The Hello World Example

Just follow the next steps:

  1. Create a new file named hello.clj and save it in the Home folder.
  2. Write and save the following code in the “hello.clj” file:
    (ns hello
      (:gen-class))

    (defn helloWorld []
      (println "Hello World!"))
      
    (helloWorld)
  3. Open the terminal from the Home folder and run the following command: clj -M hello.clj


Additional Information

For more information about the Clojure language and the corresponding code, you can check the following pages:

Something to say ?

If you want to add something about the language or about this post, please feel free to do it by commenting below 🙂 .