In this section you will learn about assigning (binding) names to values.

We will introduce the following functions for the first time:

def assign a name to a value (a value being a number, string, collection or function)
str join values together to form a single string

Give yourself a name with def

The function def can be used to give a name to something, or more specifically we are defining a name for a value. For example, you can give a name to a string or number and most other things in Clojure.

Define a name that contains a string of your name (or any name you prefer)


(def my-name "John Stevenson")

Once you define a name on a page, that name can be used with any other code on the same page

Using names

To get the value of a name you can simply use the name in your code


my-name

Define names for other things

You can define names for many things in your code. By giving a name to something, it makes it very easy to use those things elsewhere in your code just by using the name.

Using the def function to give a name to something means that you only need to change your code in one place, in the def function, your code will then use the new version.

Assign names to information about yourself



The str function

The str function is used to join strings together, returning a new string as the result. The str function can also be used to join other values, such as numbers, where those numbers are made part of the new string that is returned

(str "I can" " " "join strings" " " "and other values" " " "together")
;; (str "I can join" " " 1 " " "or more string")
;; (str "I return" " " 1 " " "string as a result")

Using names with functions

Its much more common to use a name with a function, rather than just using the name by itself.

Join names you defined with another String

Use str with one of the names you have define with def and join it to a string


()

See the example solution