Want to learn Clojure? It doesn't have to be hard!
Maybe you've heard of Clojure. Maybe you even tried to learn it. If you did, you may have had some of these problems:
- Trouble getting Clojure installed and working
- What text editor should you use?
- The syntax is foreign and strange
- There's so much to learn
- What practical thing can you even build?
These problems are hard to figure out on your own, and many tutorials skip over these. Wouldn't it be nice if you had:
- A clear guide to installing Clojure on your system
- A great text editor without installing anything new
- A gentle introduction to the syntax without dwelling on it
- Someone teach you just what you need to learn right when you need it
- A fun, engaging activity to get you programming right away
Let me tell you about ...
Introduction to Clojure (v2)
Introduction to Clojure is a gentle tutorial for Clojure. It will get you started quickly and painlessly. You'll teach a robot how to bake cookies, cake, and brownies--and learn Clojure along the way!
This is the updated and expanded course that has been used by hundreds of people to learn Clojure over the years.
Introduction to Clojure v2
Want this course?
Love it or leave it guarantee
If you don't learn as much from this course as you thought, just ask for a refund within 30 days and I'll give you your money back.
How to use the course. What is Clojure and why do people use it? How to get set up for the course.
2. Introducing X5 and JC
We introduce X5, who wants to be a baker. He's going to baking school. JC is his baking instructor. We'll be helping X5 learn, by using Clojure.
3. Working with the REPL
We start off our journey by baking some cookies and a cake. We learn how to use each ingredient and how to follow recipes.
7. Defining scooped?
We write a function that can tell us whether we need to scoop an ingredient.
11. Looping a number of times
Let's learn how to iterate a certain number of times using dotimes.
13. Variadic functions
We learn to write functions that can take a variable number of arguments and use a common pattern for handling default argument values.
14. Baking with variadic functions
Now we can rework our bake-cake function to use the variadic versions of our add functions.
15. Bake cookies function
We can now define a function called bake-cookies to implement the cookies recipe we thought before.
16. Day 1 Conclusion
Let's wrap up our first day at the bakery and take a look at what we've accomplished.
17. Running Leiningen projects
In this first lesson, we'll take a tour of a Clojure project and learn how to run it. We'll also take a look at the editor we'll be using to edit the code for the rest of the course.
19. Refactoring errors
Let's now use the error function we just wrote and replace all of the error expressions we've already got with calls to it.
20. Bakery locations
We learn about the different locations that X5 can go to in the bakery. We learn about sets and what they can hold.
21. Scooped?, squeezed?, and simple? refactor
We refactor scooped?, squeezed?, and simple? to use the same pattern we just wrote.
22. Fetching ingredients
We need to go fetch ingredients from different locations. Let's write a function that will go to the right location and fetch an ingredient and bring it back to the prep area.
23. Fetch ingredients generic
We can now write a function that will just take the ingredient as an argument and decide where to go to fetch it.
25. Fetching a shopping list
We learn a new conditional and how we can begin fetching an entire shopping list with as few trips as possible.
26. Refactoring fetch-list
We start to refactor our big fetch-list function into smaller parts.
27. Refactoring locations
We have some duplication. Let's learn a new loop to go through all of the locations and fetch what we need from each.
28. A day at the bakery
Now that we have an efficient way of fetching ingredients, let's handle the orders for the day.
29. Analyzing a day at the bakery
Let's take a look at the
day-at-the-bakery function and see how we can improve it.
30. Functional programming
Let's talk about Functional Programming. Then we can talk about combining ingredient lists.
We also want to be able to multiply an ingredient list. For instance, if we need to make 3 cakes, we can multiply the ingredients for a cake by 3. That's not quite as easy as adding, but it's not hard. We just need a few more things.
Now we can learn how to calculate one list from another and how to use it to multiply ingredients.
33. order to ingredients
We create a function that will take an order and return the ingredients needed to complete it.
34. orders to ingredients
Now we can write a function that takes a list of orders and gives you the whole list of ingredients you'll need to complete all of them.
36. Making one delivery
The delivery bot is annoyed that we give him one receipt per baked good. Let's fix that by grouping them by order.
38. Day 3
Today is X5's third day at the bakery. The first day, we learned how to use ingredients. In the second day, we learned how to calculate, basically plan ahead, before we started working, to make things more efficient.
Let's start with cleaning up some unused code.
We need to write a function that can take actions. We'll start with cooling the pan.
47. Bake recipe
We make a generic
bake-recipe function that looks up the steps in the database and bakes it.
49. Adding all recipes
Now that we can bake recipes, let's add the other recipes, cookies and brownies.
50. Cleaning up order to ingredients
We get rid of the ingredients listed in the definition of order->ingredients and instead look them up in the database.
51. Ingredients in the database
We need to add a section to the database about where to fetch ingredients and how to use them.
52. Refactoring scooped, squeezed, and simple
simple? to use the baking database.
53. Generic fetch ingredient
We can now do a generic
fetch-ingredient function that looks up the location in the database. That lets us get rid of the specific
54. Refactoring fetch-list (again)
Currently, we've defined a map called
locations that lists the locations of all of the ingredients. It's duplicating what's in the database.
We learn a new tool, called
group-by, that will allow us to drive the fetching of an entire list of ingredients by that list alone.
55. Make storage-location more useful
I'm not completely happy with
storage-location. It's not a very valuable function outside of this one usage. We should really use a custom function just for the item-amount usage.
Guide to baking for the intrepid robot