Free Sample
+ Collection

Clojure for Domain-specific Languages

Ryan D. Kelker

Enhance your existing Clojure know-how with this example-packed tutorial on building custom languages. It will help you unlock the potential of Clojure in a way you probably never thought possible.
RRP $32.99
RRP $54.99
Print + eBook

Want this title & more?

$16.99 p/month

Subscribe to PacktLib

Enjoy full and instant access to over 2000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

Book Details

ISBN 139781782166504
Paperback268 pages

About This Book

  • Explore DSL concepts from existing Clojure DSLs and libraries
  • Bring Clojure into your Java applications as Clojure can be hosted on a Java platform
  • A tutorial-based guide to develop custom domain-specific languages

Who This Book Is For

If you've already developed a few Clojure applications and wish to expand your knowledge on Clojure or domain-specific languages in general, then this book is for you. If you're an absolute Clojure beginner, then you may only find the detailed examples of the core Clojure components of value. If you've developed DSLs in other languages, this Lisp and Java-based book might surprise you with the power of Clojure.

Table of Contents

Chapter 1: An Overview of Domain-specific Languages with Clojure
Domain-specific languages (DSL)
Internal versus External DSLs
Database domains
The HTML domain
The ECMA/JavaScript domain
The Audio domain
Image domains
Chapter 2: Design Concepts with Clojure
Every function is a little program
Each function only does one thing
Patterns for success
Chapter 3: Clojure Editing and Project Creation
The origin of Emacs and its usage
Installing and setting up Emacs24
Setting up Emacs
Creating and editing CLJ files in Emacs
Running a Clojure REPL inside Emacs
Leiningen and project management
Installing Leiningen and starting a project
Including Clojure or Java libraries in your project
Chapter 4: Features, Functions, and Macros
Java inside Clojure
Dynamic objects
Lazy sequences
Functions and arity
Anonymous functions
Chapter 5: Collections and Sequencing
:let, :while, and :when
Chapter 6: Assignment and Concurrency
Chapter 7: Flow Control, Error Handling, and Math
Flow control
Object comparison
Error handling
Chapter 8: Methods for Abstraction
Creating and constructing classes
Overriding methods with reify and proxy
Custom symbol definitions with macros
Multimethod polymorphism
Relationships with hierarchies
Assertion testing with metadata
Input constraints with :pre
Output constraints with :post
Chapter 9: An Example Twitter DSL
Creating Java-based abstractions
Examples of our Twitter DSL
Reading the OAuth configuration
Making our most important macro
Handling search queries
Handling tweets
Adding user-related features
Chapter 10: Unit Testing
Exploring the clojure.test framework
The expectations framework
The midje framework
The speclj framework
Chapter 11: Clojure DSLs inside Java
Making a Java-callable Clojure class
Data hiding
Java-wrapping your Clojure

What You Will Learn

  • Understand the pros and cons of a domain-specific language
  • Learn general programming design concepts
  • Know the benefits of a Lisp-based syntax
  • Edit Clojure files in Emacs
  • Learn to operate a Read-Evaluate-Loop session from within Emacs
  • Build Clojure projects with Leiningen
  • Manipulate and make polymorphic objects in a non-object-oriented language
  • Create a Twitter domain-specific language to understand Clojure, its Java, and Lisp foundation closely.
  • Use your Clojure applications inside of a Java project

In Detail

Clojure is a very new and rapidly growing language that runs on top of the JVM. The language being hosted on the Java platform allows for Clojure applications to use existing Java components. Although there are objects in Clojure, the language is not object oriented.

"Clojure for Domain-specific Languages" is an example-oriented guide to building custom languages. Many of the core components of Clojure are covered to help you understand your options when making a domain-specific language. By the end of this book, you should be able to make an internal DSL. Starting with a comparison of existing DSLs, this book will move on to guide you through general programming, Clojure editing, and project management. The chapters after that are code oriented.

"Clojure for Domain-specific Languages" tries to expose you to as much Clojure code as possible. Many of the examples are executed in a Read-Evaluate-Print-Loop environment, so the reader can also follow along on their own machine. This book uses Leiningen, but no prior knowledge of it is required.

"Clojure for Domain-Specific Languages" aims to make you familiar with the Clojure language and help you learn the tools to make your own language.


Read More