Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Clojure for Domain-specific Languages
Table of Contents
Clojure for Domain-specific Languages
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers and more
Why Subscribe?
Free Access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. An Overview of Domain-specific Languages with Clojure
Domain-specific languages (DSL)
Limited scope
Syntax
Using a DSL
Popular DSLs
A contract between language and domain
The language of trust
Internal versus External DSLs
External DSLs
Internal DSLs
Clojure libraries
The characteristics of a Clojure library
The current state of Clojure libraries
Database domains
The HTML domain
Formative
Hiccup
Mustache
Clostache
The ECMA/JavaScript domain
ClojureScript
Comparing ClojureScript and JavaScript
The Audio domain
Music-as-data
Overtone
Image domains
Summary
2. Design Concepts with Clojure
Every function is a little program
A pure function
Floor-to-roof development
Each function only does one thing
Patterns for success
DRY
KISS
YAGNI
Writing Clojure
Spacing and alignment
Syntax
Name conventions
Collection types
Summary
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
The nrepl.el Emacs extension
Testing the setup
Leiningen and project management
Installing Leiningen and starting a project
Including Clojure or Java libraries in your project
Compiling your project to a Java JAR
Leiningen
Summary
4. Features, Functions, and Macros
Namespaces
Java inside Clojure
Immutability
Dynamic objects
Metadata
Lazy sequences
Destructuring
Functions and arity
Anonymous functions
Macros
Summary
5. Collections and Sequencing
Collections
Collections by example
Vectors
Vectors by example
Lists
Lists by example
Maps
Maps by example
Sets
Sets by example
Sequences
Sequences by example
:let, :while, and :when
Summary
6. Assignment and Concurrency
Variables
Transients
Atoms
Agents
Refs
Futures
Promises
Summary
7. Flow Control, Error Handling, and Math
Flow control
Object comparison
Casting
Error handling
Arithmetic
Addition and subtraction
Multiplication
Division
Remainder and modulus
Increment and decrement
Greatest and least values
Equality
Summary
8. Methods for Abstraction
Creating and constructing classes
Creating interfaces and implementing them with deftype
Using records, protocols, and type extensions
Overriding methods with reify and proxy
Working with reify
Implementing interface methods with proxy
Custom symbol definitions with macros
Definitions using records
Making definitions using proxy
Making definitions using deftype
Multimethod polymorphism
Creating the Bottle and Customer classes
Testing the customer-drink methods
Relationships with hierarchies
Resolving parent relationship conflicts
Assertion testing with metadata
Input constraints with :pre
Output constraints with :post
Summary
9. An Example Twitter DSL
Creating Java-based abstractions
Making Java objects easier to manipulate
Retrieving values in a better way
Examples of our Twitter DSL
The Retweet bot
Creating an event notifier
Reading the OAuth configuration
Twitter account registration and application keys
Adding required dependencies
Creating the project and API configuration
Reading the Twitter configuration
Making our most important macro
Building the deftwitter macro
Building the twitter-> macro
Handling search queries
Adding the tdsl.search namespace
Search macros and functions
Handling tweets
Adding the tdsl.tweet namespace
Tweet macros and functions
Adding user-related features
Adding the tdsl.user namespace
User macros and functions
User details and multimethods
Adding logging features
Summary
10. Unit Testing
Exploring the clojure.test framework
Testing tdsl.core
Using the is macro
Using the are macro
Developing the final test
The expectations framework
Using the expect macro
Search testing
The midje framework
Using the fact macro
The speclj framework
Using the describe, it, should, and should= macros
Using the should-contain macro
Summary
11. Clojure DSLs inside Java
Making a Java-callable Clojure class
Class naming
Data hiding
AOT – the ahead-of-time compilation
Java-wrapping your Clojure
Summary
A. References
Chapter 1: An Overview of Domain-specific Languages with Clojure
Chapter 2: Design Concepts with Clojure
Chapter 3: Clojure Editing and Project Creation
Chapter 4: Features, Functions, and Macros
Chapter 5: Collections and Sequencing
Chapter 6: Assignment and Concurrency
Chapter 7: Flow Control, Error Handling, and Math
Chapter 8: Methods for Abstraction
Chapter 9: An Example Twitter DSL
Chapter 10: Unit Testing
Chapter 11: Clojure DSLs inside Java
Index
← Prev
Back
Next →
← Prev
Back
Next →