Infix vs. prefix notation

In Clojure, +, -, * and / appear before two numbers. This is
called prefix notation. What you’re used to seeing is called
infix notation, as the arithmetic operator is in-between the two
operands.

Languages such as JavaScript use infix notation,
while Clojure only uses prefix notation.
Prefix notation is useful for many reasons. Look at this example of
an infix expression and the prefix equivalent:

The benefits of prefix notation

Explicit precedence

Imagine both are unclear, but notice that in the prefix version,
you do not have to ever think about the precedence of operators.
Because each expression has the operator before all the operands and
the entire expression is wrapped in parentheses, all precedence is
explicit.

Infix: 1 + 2 / 3
Prefix: (+ 1 (/ 2 3))

Less repetitive

Another reason prefix notation can be nice is that it can make long
expressions less repetitive.
With prefix notation, if we plan to use the same operator on many
operands, we do not have to repeat the operator between them.

Arithmetic with all number types

So far, we looked at arithmetic operations by integers only.
However, we can use floats or ratios for those operations as well.
See these examples:

(+ 4/3 7/8) ;=> 53/24
(- 9 4.2 1/2) ;=> 4.3
(/ 27/2 1.5) ;=> 9.0

Strings

What is a string? A string is just a piece of text. To make a
string, you enclose it in quotation marks.
Look at the last example. A backslash is how we put a quotation mark
inside a string. Do not try using single quotes to make a string.

"Hello, World!"
"This is a longer string that I wrote for purposes of an example."
"Aubrey said, \"I think we should go to the Orange Julius.\""

Booleans and nil

A boolean is a true or false value, and you type them just like that,
true and false. Often in programming, we need to ask a true or
false question, like “Is this class in the current semester?” or “Is
this person’s birthday today?” When we ask those questions, we get a
boolean back.

There is another value nil, which behaves like a boolean in terms
of truthiness.
But, nil means no value at all and not a boolean

Keywords

Keywords are the strangest of the basic value types. Some computer
languages have similar one. However, keywords don’t have a real
world analog like numbers, strings, or booleans.
You can think of them as a special type of string, one that’s used for
labels. They are often used as keys of key-value pair for maps (data
structure; will learn later).

:forename
:surname
:date-of-birth

Defining names

If we had to type the same values over and over, it would be very
hard to write a program. What we need are names for values, so we
can refer to them in a way we can remember.

Defining names for values: let

Most of the time, we only need a name for a short time. To help
ourselves keep track of our names, we define short-term names with
let. The nice thing about let is that it keeps our names
tidy. The name we create is only defined within the let.

(let [mangoes 3
oranges 5]
(+ mangoes oranges))
;=> 8

Defining names for values: def

Sometimes, we need a name that doesn’t fit in a let. We prefer to
limit how many names we use, but sometimes we need a few names
across our entire program. For those cases, we can define a name for
a value using def. When a name is defined, that name is called a
symbol.

(def mangoes 3)
(def oranges 5)
(+ mangoes oranges)
;=> 8

EXERCISE 1: Basic arithmetic

How many minutes have elapsed since you arrived at the workshop today?