PacktLib: Clojure for Domain-specific Languages

Clojure for Domain-specific Languages

Credits

About the Author

About the Reviewers

www.PacktPub.com

Preface

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

Design Concepts with Clojure

Every function is a little program

Each function only does one thing

Patterns for success

Summary

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

Features, Functions, and Macros

Namespaces

Java inside Clojure

Immutability

Dynamic objects

Metadata

Lazy sequences

Destructuring

Functions and arity

Anonymous functions

Macros

Summary

Collections and Sequencing

Collections

Vectors

Lists

Maps

Sets

Sequences

:let, :while, and :when

Summary

Assignment and Concurrency

Variables

Transients

Atoms

Agents

Refs

Futures

Promises

Summary

Flow Control, Error Handling, and Math

Flow control

Object comparison

Casting

Error handling

Arithmetic

Summary

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

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

Unit Testing

Exploring the clojure.test framework

The expectations framework

The midje framework

The speclj framework

Summary

Clojure DSLs inside Java

Making a Java-callable Clojure class

Data hiding

Java-wrapping your Clojure

Summary

References

References

References

References

References

References

References

References

References

References

References

References

Index