Introduction

Introduction

How to use the course. What is Clojure and why do people use it? How to get set up for the course.

Code

Code is available: lispcast/introduction-to-clojure

You can checkout the code in your local repo with this command:

$CMD git clone https://github.com/lispcast/introduction-to-clojure.git 
$CMD cd introduction-to-clojure        

Notes


How to use this course

This course is designed to introduce you to Clojure slowly but surely. It's an interactive course meant to give you the skills you need--from the thinking skills to the typing skills--to write Clojure. Please follow along with code as I type and do the exercises. This is not a lecture format where you can sit back and simply absorb lots of material. It's all about getting into the code.

So just remember a few things:

  1. Whenever you see some code that I type, you should type it, too. Pause the video if you have to.

  2. Whevever there's an exercise, pause the video and do it. I'll show my version immediately after.

  3. If you get lost, don't worry. All of the code is available to copy-paste and in the git repo. There are commands in the notes for switching to any version of the code. And you can reset the state of the bakery at any time.

  4. Pause and rewind all you want.

  5. Most importantly, play around and have fun!

And have fun!


What you'll need to follow this course

You will need Java JDK and Leiningen installed, as well as git. You can find Java Leiningen install guides for all the major platforms here.

You will also need a terminal (command prompt) and a web browser. These are usually installed on all computer systems.

Finally, you need to install Git. Git is a software repository system. It will let you fetch and navigate the source code. Don't worry, all the commands will be given to you. Please follow the install guide for Git here.


Getting the code

There is a git repo with all of the code that we type. You can get the code by running this at the terminal:

$CMD git clone https://github.com/lispcast/introduction-to-clojure.git

The code will differ slightly from the video since the code is kept up to date with new releases to make sure it still runs.

There are git "tags" set up to navigate the code at different points in the video. You can find the command to switch to different git tags throughout the notes (this document). I suggest you clone two copies of the repo. You can use one to follow along and do exercises and one as a clean reference.

Here's how to clone the second copy of the repo. This one you should keep clean (don't modify anything) so that you can navigate around a known working version of the code.

$CMD git clone https://github.com/lispcast/introduction-to-clojure.git introduction-to-clojure-clean


What is Clojure?

Clojure is a programming language, developed originally by Rich Hickey, to run on the Java Virtual Machine (JVM). The Java Virtual Machine is a widely supported runtime. Many companies, large and small, have JVM deployments, and Clojure can run on all of them. In fact, Clojure was designed to interoperate well with its host.

People choose Clojure for a number of reasons.


Dynamic Development

In many, you write code in a text file. Then you compile it. Then run the program starting from nothing. This style of development gives a very slow feedback loop. It can take many seconds to test code you just wrote. Clojure was built to support dynamic development with fast feedback. You start a Clojure system and interact with it, including writing and running code. Your feedback loop is much faster and it's easier to understand your code.

Everything is available to you: the compiler, creating variables, instatiating objects, running your tests, etc. We'll be using a built-in command prompt called a Read Eval Print Loop (REPL) to interact with the system. We'll also use text files for code we'd like to keep.


Functional Programming

Java is considered to be an Object-Oriented (OO) language. Now, you can do any paradigm in any language, but Java makes Object-Oriented Programming the default and easy method. Clojure makes a different choice. Clojure is well-suited to Functional Programming (FP). If Functional Programming is a better fit for the problems you are solving, then Clojure might be a good match.


Data-orientation

When we write software, we're often writing information systems. In software, the information we process is called data. Clojure puts data front-and-center. Much of what we'll be learning in this course is how to model a problem as data and how to process it.

There are many other reasons, but these are the ones we'll be exploring in this course.

Now let's get started!

B01 Introduction to Clojure (old version)

Buy nowLearn more
  • Introduction9

Day 1

  • Introducing X5 and JC
  • Working with the REPL3
  • Defining functions
  • Defining a bake-cake function
  • Conditionals10
  • Defining scooped?
  • Defining squeezed?
  • Defining simple?2
  • Defining ingredient types2
  • Looping a number of times6
  • Using the plural functions2
  • Variadic functions8
  • Baking with variadic functions4
  • Bake cookies function
  • Day 1 Conclusion2

Day 2

  • Running Leiningen projects16
  • Error function10
  • Refactoring errors
  • Bakery locations
  • Scooped?, squeezed?, and simple? refactor2
  • Fetching ingredients4
  • Fetch ingredients generic
  • Maps
  • Fetching a shopping list
  • Refactoring fetch-list1
  • Refactoring locations2
  • A day at the bakery5
  • Analyzing a day at the bakery
  • Functional programming2
  • Into2
  • multiply-ingredients2
  • order to ingredients
  • orders to ingredients
  • Making one shopping trip
  • Making one delivery
  • Day 2 conclusion

Day 3

  • Day 3
  • Add cocoa
  • Baking brownies
  • Analyzing recipes1
  • Starting the database
  • Perform
  • Mix step
  • Pouring and baking
  • Adding ingredients2
  • Bake recipe
  • Generic bake function
  • Adding all recipes1
  • Cleaning up order to ingredients
  • Ingredients in the database
  • Refactoring scooped, squeezed, and simple2
  • Generic fetch ingredient
  • Refactoring fetch-list (again)1
  • Make storage-location more useful
  • Redefining add
  • Defining actions
  • Refactoring perform1
  • Conclusions1

Appendices

  • Appendix: Creating a Leiningen project