Skip to content

Commit

Permalink
Merge pull request ClojureBridge#133 from kpfell/update-slides-2
Browse files Browse the repository at this point in the history
Update slides/curriculum for module2.html
  • Loading branch information
bridgethillyer committed Feb 8, 2015
2 parents d0902c2 + 5129847 commit 5d67015
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions outline/data_structures.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ What can you do with vectors? Vectors are easy to add more items to, delete item
;=> (10 15)
```

Let's look at these functions together. First, you see a function called `vector?`. You can probably guess what that does: it tells us whether the argument is a vector. Notice that it has a question mark at the end of it. We often call functions like these _predicate functions_, and they answer true-or-false questions about the data we give them.
Let's look at these functions together. First, you see a function called `vector?`; this tells us whether the argument is a vector. Notice that it has a question mark at the end of it. We often call functions like these _predicate functions_, and they answer true-or-false questions about the data we give them.

The next two functions are used to make new vectors. The `vector` function takes any number of items and puts them in a new vector. `conj` is an interesting function that you'll see used with all the data structures. With vectors, it takes a vector and an item and returns a new vector with that item added to the end of the vector. Why the name `conj`? The verb "conjugate" has an archaic meaning "to join together," which is what we're doing: we're joining the new item to the vector.

If you've programmed in another language before, you might be wondering if `conj` changes the vector. It's important to note that it does not. All collections in Clojure are _immutable_--that is, unchangeable. When we say that a function "adds to" or "removes from" a collection, what we mean is that the function returns a new collection with an item added or removed.

Now, take a look at the last three functions. `count` does what you'd expect: it gives us a count of the number of items in a vector. `nth` gives us the nth item in the vector. Note that we start counting at 0, so in the example, calling `nth` with the number 1 gives us what we'd call the second element when we aren't programming. `first` returns the first item in the collection. Try not to think about that and `nth` at the same time or your brain will fry.
Now, take a look at the last three functions. `count` gives us a count of the number of items in a vector. `nth` gives us the nth item in the vector. Note that we start counting at 0, so in the example, calling `nth` with the number 1 gives us what we'd call the second element when we aren't programming. `first` returns the first item in the collection. Try not to think about that and `nth` at the same time, as they can be confusing.


### EXERCISE: Make a vector
Expand Down
7 changes: 3 additions & 4 deletions slides/module2.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ <h3 class="slide-title slide">Vector functions</h3>
<h3 class="slide-title slide">Exercise: Make a
vector</h3>

<p>Make a vector of the high temperatures for the next 7
days in the town where you live. Then use the
<code>nth</code> function to get the high temperature for
next Tuesday.</p>
<p>
Make a vector of the high temperatures for the next 7 days in the town where you live. Then use the <code>nth</code> function to get the high temperature for next Tuesday.
</p>
</section>
</div>
</div><script src="assets/reveal.js/lib/js/head.min.js">
Expand Down

0 comments on commit 5d67015

Please sign in to comment.