Clojure for Domain-specific Languages

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.

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.
Mapt Subscription
FREE
$29.99/m after trial
eBook
$23.10
RRP $32.99
Save 29%
Print + eBook
$54.99
RRP $54.99
What do I get with a Mapt Pro subscription?
  • Unlimited access to all Packt’s 5,000+ eBooks and Videos
  • Early Access content, Progress Tracking, and Assessments
  • 1 Free eBook or Video to download and keep every month after trial
What do I get with an eBook?
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with Print & eBook?
  • Get a paperback copy of the book delivered to you
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with a Video?
  • Download this Video course in MP4 format
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
$0.00
$23.10
$54.99
$29.99p/m after trial
RRP $32.99
RRP $54.99
Subscription
eBook
Print + eBook
Start 30 Day Trial
Subscribe and access every Packt eBook & Video.
 
  • 5,000+ eBooks & Videos
  • 50+ New titles a month
  • 1 Free eBook/Video to keep every month
Start Free Trial
 
Preview in Mapt

Book Details

ISBN 139781782166504
Paperback268 pages

Book Description

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.

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
Summary
Chapter 2: Design Concepts with Clojure
Every function is a little program
Each function only does one thing
Patterns for success
Summary
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
Leiningen
Summary
Chapter 4: Features, Functions, and Macros
Namespaces
Java inside Clojure
Immutability
Dynamic objects
Metadata
Lazy sequences
Destructuring
Functions and arity
Anonymous functions
Macros
Summary
Chapter 5: Collections and Sequencing
Collections
Vectors
Lists
Maps
Sets
Sequences
:let, :while, and :when
Summary
Chapter 6: Assignment and Concurrency
Variables
Transients
Atoms
Agents
Refs
Futures
Promises
Summary
Chapter 7: Flow Control, Error Handling, and Math
Flow control
Object comparison
Casting
Error handling
Arithmetic
Summary
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
Summary
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
Summary
Chapter 10: Unit Testing
Exploring the clojure.test framework
The expectations framework
The midje framework
The speclj framework
Summary
Chapter 11: Clojure DSLs inside Java
Making a Java-callable Clojure class
Data hiding
Java-wrapping your Clojure
Summary

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

Authors

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
Summary
Chapter 2: Design Concepts with Clojure
Every function is a little program
Each function only does one thing
Patterns for success
Summary
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
Leiningen
Summary
Chapter 4: Features, Functions, and Macros
Namespaces
Java inside Clojure
Immutability
Dynamic objects
Metadata
Lazy sequences
Destructuring
Functions and arity
Anonymous functions
Macros
Summary
Chapter 5: Collections and Sequencing
Collections
Vectors
Lists
Maps
Sets
Sequences
:let, :while, and :when
Summary
Chapter 6: Assignment and Concurrency
Variables
Transients
Atoms
Agents
Refs
Futures
Promises
Summary
Chapter 7: Flow Control, Error Handling, and Math
Flow control
Object comparison
Casting
Error handling
Arithmetic
Summary
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
Summary
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
Summary
Chapter 10: Unit Testing
Exploring the clojure.test framework
The expectations framework
The midje framework
The speclj framework
Summary
Chapter 11: Clojure DSLs inside Java
Making a Java-callable Clojure class
Data hiding
Java-wrapping your Clojure
Summary

Book Details

ISBN 139781782166504
Paperback268 pages
Read More

Read More Reviews

Recommended for You

Clojure for Machine Learning Book Cover
Clojure for Machine Learning
$ 29.99
$ 21.00
Clojure Data Analysis Cookbook Book Cover
Clojure Data Analysis Cookbook
$ 32.99
$ 23.10
Clojure Reactive Programming Book Cover
Clojure Reactive Programming
$ 35.99
$ 25.20
Clojure Web Development Essentials Book Cover
Clojure Web Development Essentials
$ 26.99
$ 18.90
Mastering Clojure Data Analysis Book Cover
Mastering Clojure Data Analysis
$ 35.99
$ 25.20
Mastering Web Application Development with AngularJS Book Cover
Mastering Web Application Development with AngularJS
$ 26.99
$ 5.40