Eric Normand Courses/B03 Clojure Language Basics

  • $75

B03 Clojure Language Basics

  • Closed

Contents

Variables and scope

We use a lot of variables in code and a lot of names. We need rules for how they work—especially when they conflict. We want those rules to make our lives easier. We don't want to accidentally refer to the wrong variable or to unexpectedly have it change the meaning.

That's what the scoping rules are all about. They tell us what each variable in our code refers to, even when there are duplicate names. If we master these rules, we can be confident that our code will do what we mean. And we can make the choices that are right for our new code.

Global Scope
Let and Function Argument Scope
Dynamic Scope
Scope problems diagnosed

Namespaces

Namespace declarations can be complicated. They manage all of the dependencies of one namespace on another. There are a lot of options. Would you like to know:
  • How to choose between :use, :require, and :import
  • When do you use an apostrophe, and when do you need a vector?
  • How to make it work with ClojureScript
  • How to work at the REPL with namespaces
  • How to import Java classes
Namespaces are required knowledge for working in Clojure and ClojureScript. They can be hard to learn to manage, but once you do, they are rarely a problem.
Clojure Namespace Declarations
Navigating Namespaces at the REPL

Syntax

for comprehensions
Clojure Function Syntax

Collections

Clojure is based on collections, but how are they used? What are the patterns for making the most of them? This section introduces you to the workhorses of the Clojure programming language, the immutable collections. We go over every built-in collection, how they are used, and when you should use them.
Introduction to Clojure's Collections
Preview
Data structures
Vector collection
HashMap collection
Set collection
List collection
Queue collection
Sorted Map collection
Sorted Set collection
Access patterns
Sequential Access Pattern
Remembering Duplicates Access Pattern
Lookup by key Access Pattern
Associate key and value Access Pattern
Dissociate a key and value Access Pattern
Count the elements Access Pattern
Equality Comparison Access Pattern
Removing an item from a set Access Pattern
Splitting a sequence Access Pattern
Containment Check Access Pattern
First-in, first-out Access Pattern
Last-in, First-out Access Pattern
Usage patterns
Entity Usage Pattern
Index Usage Pattern
Tuple Usage Pattern
Multi-comparison Usage Pattern
Transients
Usage in an Atom
Hybrid Collections
Hybrid Types
Vectors and Lists in syntax
Lazy sequences
Collections vs sequences

Lazy sequences

Clojure sequences are lazy by default. They're a common source of errors in Clojure software. What's worse, the error messages do not give much clues that the error has to do with laziness. They can be frustrating, but they're worth learning for the power they give you. Here's what you need to learn:

  • What they are and how to think about them
  • How to avoid the most common gotchas
  • The benefits of laziness and how to make them work for you
This section is designed to get you over the major hurdles of lazy sequences so you can start enjoying the separation of concerns that Clojure's lazy sequences grant you.
What are lazy sequences?
Gotcha: Effects and chunking
Gotcha: *print-length*
Gotcha: holding onto the head
Gotcha: length checks
The Benefits of Laziness

Destructuring

Ever wonder how to read those destructuring forms? Destructuring can be very confusing because it is so terse. When it's unfamiliar, it can be totally opaque. Once you learn it, though, you'll be using it all of the places.

This section introduces the idea of destructuring and goes through all of the possible ways to do destructuring in Clojure and when the forms should be used. You'll make your code clearer and shorter.

Introduction
Sequences
Maps Part 1
Maps Part 2
Keyword Arguments
Where to Destructure
Nested Destructuring
Destructuring Examples

Concurrency

You've heard that Clojure is great for concurrency. But what tools does Clojure give you? And how should you use those tools? There are a lot of tools available, and each has its strengths and weaknesses. It can be difficult to learn how to choose between them. But once you do, you'll be firing up threads left and right to get work done in parallel.

These lessons are meant to each answer a specific question and help you build the skills you need to address a wide variety of concurrency problems.
Delay
Promise
Future
Deref
Keeping state consistent with Atoms
Sharing state among many threads: Atoms
Ref
Vars
Agents
Locking
Core Async
Threads
ExecutorService
ForkJoin
Reducers

Protocols

There's a big problem in software. You've got all these different types, and all of these different roles they play in your software. But sometimes you can't modify the code for the type. Maybe it's in a Java class in a library. Clojure's protocols let you solve this. You can extend existing classes or build protocols into new types.

When you have different types filling the same roles, we call that polymorphism. Clojure uses protocols for polymorphism. They are totally extensible on "both ends". You can extend existing types with new roles. And you can fill existing roles with new types. They let you create very flexible software with little effort.

In this course, you will learn:

  • What problem protocols solve (it's called "The Expression Problem")
  • How to define new protocols
  • How to extend types with protocols
  • Three cool uses for protocols
What Problems do Clojure Protocols Solve?
How to define protocols
Protocols for Easy Type Conversion
Defining a DSL with Protocols
Building a Component Clone

  • $75

B03 Clojure Language Basics

  • Closed