Module 1 - Practice - Basic Clojure

Exercise 0:

  • How to make a copy of a pre-existing Nextjournal notebook that you can edit

  • How to create a new Clojure code cell

  • How to undo one or more changes to a notebook

  • Bonus: How to delete a cell

  • Bonus: How to move a cell up or down

{:deps {org.clojure/clojure {:mvn/version "1.10.3"}
        ;; complient is used for autocompletion
        ;; add your libs here (and restart the runtime to pick up changes)
        compliment/compliment {:mvn/version "0.3.9"}}}
Extensible Data Notation
{:hello (clojure-version)}
0.1s

Exercise 1:

Create a variable that has an integer value and another variable that has a float value. Write code that prints the product (multiply the two together).

Hint: To multiply numbers in Clojure, use the asterisk sign (*).

;; Here is a code cell for you to use for exercise 1

Can you figure out how to make a new code cell for exercise 2? If you need them, the instructions are written at the bottom of this notebook.

Exercise 2:

Make a list of all the months in the year. Write code that uses a loop, list comprehension, or mapping function to go through the list, print out the month and the number of characters (length) for each month word.

Exercise 3:

Create a map with keys "movie" and "season", with the values being your favorite movie and season. Then write code to print out "My favorite [key] is [value]".

Exercise 4:

Create a customized function (defn) that divides two numbers and returns the result of their division. Then, print out the result of calling your function using the variables you made in Exercise 1.

Hint: To divide numbers in Clojure, use the forward slash (/).

How to Make a New Cell

To make new code cells in Nextjournal, you can simply move your mouse over a pre-existing cell (text or code). You should see that a + icon has appeared immediately to the bottom left corner of the cell. Try clicking on that + icon.

You've reach the bottom of this notebook! Click here to go back to the top of this notebook.

Runtimes (1)