Alan is a developer at Relevance, where he specializes in web applications. He is a frequent contributor to the Clojure language, and has also contributed to several popular Clojure libraries. At Relevance, he's built Clojure software for a range of clients, in domains ranging from online gaming to network security.
Section Introduction Transcripts
Section Introduction Transcripts
Functions Hi, I'm Alan Dipert and in this module, we're going to talk about functions. Clojure is a functional programming language and as such, functions are a big part of programming and Clojure. And one way to think about them is the building block or the fundamental abstraction that Clojure programs tend to be built upon. In Clojure, functions are first class which means that a function object is treated like any other value and can be passed to other functions for instance, the same way a value might. Clojure also has support for higher ordered functions which are functions that could take functions as arguments. That's simply an implication of functions being first class. It's common in Clojure code to have pure functions. These are functions that do not have side effects in are closer to being the functions you might recognize from math than they are to same methods from programming languages you might be familiar with. We'll investigate what all these means and along the way, we'll take look at apply which is a way to apply a collection of data to a function as if it were an argument list and we'll also take a look at let which is a way in Clojure to create lexical scopes. Finally, we'll take a look at what method invocation and Clojure looks like and why it's different than function invocation. ( Pause )
Namespaces Hello, I'm Alan Dipert and this is the names and namespaces module. Modularization is an important part of writing extensible, reusable, and understandable programs. Namespaces are a modularization tool in Clojure. They allow us to divide named things like functions or pieces of data into namespaces. A single Clojure program may have multiple namespaces. The division of names into namespaces makes naming easier because we have to worry less about the possibility of collisions. So, let's learn about Clojure's namespace system and the tools Clojure provides for working with namespaces.
Collections Clojure comes with a rift (phonetic) set of collection data structures. Beyond the list, Clojure has literal support for maps or dictionaries, sets and vectors which are similar to arrays. Every closure collection is immutable, which means it cannot be updated in place. Instead of mutating collections, Functions and Clojure tend to take them as arguments and then return new collections without affecting the original. The immutability of Clojure data is part of what makes concurrent programming in Clojure easier. In this module, we'll learn about the syntax and characteristics of Clojure's collection data structures. We'll also explore the API Clojure provides for working with these collections. The computer scientist Alan Perlis once said, "It is better to have 100 functions operate on one data structure than have 10 functions operate on 10 data structures. " His description of what is better is similar to the way Clojure encourages programmers to orient many functions around several data structures. For now, you have to trust Mr. Perlis, but hopefully, after this module and with a little more Clojure under your belt, you'll feel the same way.
Destructuring Clojure is definitely a functional programing language but all it's function are oriented around data so it may also be considered data oriented. We saw on the previous module that Clojure provides a rich set of collections and a rich set of functions for working with those collections. These functions make working with different kinds of data easier. In addition to the functions we saw, Clojure eases data work by providing a way to pull apart compound data structures concisely. This mechanism known as destructuring is a kind of mini-language embedded in Clojure that is incredibly useful. In this module, we'll learn about destructuring and use it to pull apart sequential and associative collections so that we can work with them in pieces.
Sequences The ideas of order and sequentiality are useful in programing. Traditionally we use things like loops, arrays and strings to represent and convey these ideas. Clojure provides the sequence obstruction to consolidate or use of this ideas in our programs. This consolidation makes it possible for there to exist a large library of functions for working with sequential things. In this module, we look at the sequence obstruction and its associated API. We'll also see some code examples that leverage Clojure sequences.
Flow Control Flow control is the control over which code in a program is executed. Flow control constructs are an important part of any programming language because we often need to do or not do certain things depending on some condition. Clojure provides a variety of flow control operators and a simple model for what is true and what is false. In this module, we'll learn Clojure simple Boolean semantics and apply them to flow control operators.