start content of chapter 3

rhgraysonii authored
revision 052dce959f1815703afe1834a86ea6a040389cb0
# More Types

## Symbols
Let's look at a symbol.

(class 'str)

A symbol in Clojure is a piece that allows us to reference things locally. For our purposes there is not much more that is needed in digging into them.Their most common use is to be referred to then filled in with a value.

## Booleans
If you are familiar with program concepts in general (which you should be if reading this book) you will have heard the term 'truthiness' many times before. The 'truthiness' structure of Clojure works as follows.

(boolean false)

(boolean true)

(boolean nil)

As you can see, there is little surprise here outside of nil returning false. In Ruby we would see this:


So, we now can deduce nil evaluates to false. Now, let us look at the next thing that may catch you off guard if you come from the wonderful land of C.

(boolean 0)
;=> true

Clojure's only negative return types are nil and false. Now, we can also use our standard not, and, and or operators.

(not "pants")
;=> false;

(not nil)

Not returns the opposite.

(and "pants" "are" "off")

(and false true true false)

And returns the first negative value, or the last one if all are truthy.

(or false "my pants are off")
;=>"my pants are off"

Or returns the first positive value.

## Keywords
Keywords are much like symbols. They contain a value to name something. They are much more useful when being paired with other data rather than operating on their lonesome. (They are just SO clingy)


We'll play with these rascals more once we get into maps later.

## Lists
Lists are the most integral building block of any lisp.

'("my pants are off" 9999 "hashtag coding")
;=>("my pants are off" 9999 "hashtag coding")

We also can use the keyword 'list'. It is your call.

(list "my" "pants" "are" "missing")
;=>("my" "pants" "are" "missing")

We can compare lists. It happens as you may expect.

(= '("my pants are off")("my pants are off"))

We can add to them using the conjoin command, as well.

(conj '("pants" "are off") "my")
;=>("my" "pants" "are off")

Much like in other languages, we can call first on a list.

(first ("dance" "sing" "eat" "sleep" "die")

We can also call any element we know the number of arbitrarily with the "nth" operator.

(nth ( 1 2 3 4 5 6 ) 3)

Note that indexing works in the standard way you should be used to.

## Vectors
Now, I feel like you might just be a *little* sick of parentheses. So lets check some square brackets out (trust me, they go hard in the paint too)

["my pants" "are off"]
;=>["my pants" "are off"]

Vectors don't need parentheses because they are evaluated in a different way than lists. We also can turn other things into vectors (just like we can with strings using our str command) or conjoin to them.

(vec ("definitely not wearing" "pants"))
;=>["definitely not wearing" "pants"]

(conj [1 2 3 4] "tell me that you love me more")
;=>[1 2 3 4 "tell me that you love me more"]

Note that the conjoin command adds to the end of the vector, rather than the beginning as it does if it is a list. We also have the same first and nth operators. We also have two new ones called next and rest though.

(rest ["no, I have" "no" "pants" "on"])
;=>["no" "pants" "on"]

(next ["sure glad" "I dont" "have pants on"])
;=>["I dont" "have pants on"]

The only difference between them is how they operate when evaluating an empty vector. Next will return nil and rest will return an empty list.
Other standard methods such as count and last. We also can look things up by index quite simply.

(["Harry Potter" "Ron Weasley" "Hermoine Granger"] 0)
;=>"Harry Potter"

Now, remember earlier when we described equality in Clojure? Each of these items contains a hash that tells what is inside of it. So now if we take a vector and a list to be compared, let us examine the output.

(= [1 2 3] (1 2 3)]

## Sets

## Maps