Mastering Clojure
eBook - ePub

Mastering Clojure

  1. 266 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Mastering Clojure

About this book

Understand the philosophy of the Clojure language and dive into its inner workings to unlock its advanced features, methodologies, and constructs

About This Book

  • Learn to handle data using sequences, reducers, and transducers in Clojure
  • Explore the lesser known and more advanced features, constructs, and methodologies of the Clojure language and its ecosystem, such as asynchronous channels, actors, logic programming, and reactive programming
  • Sharpen your Clojure skills through illustrative and comprehensive examples

Who This Book Is For

If you're looking to learn more about the core libraries and dive deep into the Clojure language, then this book is ideal for you. Prior knowledge of the Clojure language is required.

What You Will Learn

  • Maximize the impact of parallelization, functional composition, and process transformation by composing reducers and transducers
  • Process and manipulate data using sequences, reducers, and transducers in Clojure
  • Modify and add features to the Clojure language using macros
  • Explore the features of category theory and custom data sources for logic programming in Clojure
  • Orchestrate parallelism and concurrency using built-in primitives as well as community libraries in Clojure
  • Handle data with asynchronous and reactive programming methodologies and leverage it using the core.async library
  • Test your code with unit tests, specs, and type checks to write testable code
  • Troubleshoot and style your Clojure code to make it more maintainable

In Detail

Clojure is a general-purpose language from the Lisp family with an emphasis on functional programming. It has some interesting concepts and features such as immutability, gradual typing, thread-safe concurrency primitives, and macro-based metaprogramming, which makes it a great choice to create modern, performant, and scalable applications.

Mastering Clojure gives you an insight into the nitty-gritty details and more advanced features of the Clojure programming language to create more scalable, maintainable, and elegant applications. You'll start off by learning the details of sequences, concurrency primitives, and macros. Packed with a lot of examples, you'll get a walkthrough on orchestrating concurrency and parallelism, which will help you understand Clojure reducers, and we'll walk through composing transducers so you know about functional composition and process transformation inside out. We also explain how reducers and transducers can be used to handle data in a more performant manner.

Later on, we describe how Clojure also supports other programming paradigms such as pure functional programming and logic programming. Furthermore, you'll level up your skills by taking advantage of Clojure's powerful macro system. Parallel, asynchronous, and reactive programming techniques are also described in detail.

Lastly, we'll show you how to test and troubleshoot your code to speed up your development cycles and allow you to deploy the code faster.

Style and approach

This is an easy-to-follow project-based guide that throws you directly into the excitement of Clojure code. Mastering Clojure is for anyone who is interested in expanding their knowledge of language features and advanced functional programming.

Trusted by 375,005 students

Access to over 1.5 million titles for a fair monthly price.

Study more efficiently using our study tools.

Information

Year
2016
Edition
1
eBook ISBN
9781785889745

Mastering Clojure


Table of Contents

Mastering Clojure
Credits
About the Author
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
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. Working with Sequences and Patterns
Defining recursive functions
Thinking in sequences
Using the seq library
Creating sequences
Transforming sequences
Filtering sequences
Lazy sequences
Using zippers
Working with pattern matching
Summary
2. Orchestrating Concurrency and Parallelism
Managing concurrent tasks
Using delays
Using futures and promises
Managing state
Using vars
Using refs
Using atoms
Using agents
Executing tasks in parallel
Controlling parallelism with thread pools
Summary
3. Parallelization Using Reducers
Using reduce to transform collections
What's wrong with sequences?
Introducing reducers
Using fold to parallelize collections
Processing data with reducers
Summary
4. Metaprogramming with Macros
Understanding the reader
Reading and evaluating code
Quoting and unquoting code
Transforming code
Expanding macros
Creating macros
Encapsulating patterns in macros
Using reader conditionals
Avoiding macros
Summary
5. Composing Transducers
Understanding transducers
Producing results from transducers
Comparing transducers and reducers
Transducers in action
Managing volatile references
Creating transducers
Summary
6. Exploring Category Theory
Demystifying category theory
Using monoids
Using functors
Using applicative functors
Using monads
Summary
7. Programming with Logic
Diving into logic programming
Solving logical relations
Combining logical relations
Thinking in logical relations
Solving the n-queens problem
Solving a Sudoku puzzle
Summary
8. Leveraging Asynchronous Tasks
Using channels
Customizing channels
Connecting channels
Revisiting the dining philosophers problem
Using actors
Creating actors
Passing messages between actors
Handling errors with actors
Managing state with actors
Comparing processes and actors
Summary
9. Reactive Programming
Reactive programming with fibers and dataflow variables
Using Reactive Extensions
Using functional reactive programming
Building reactive user interfaces
Introducing Om
Summary
10. Testing Your Code
Writing tests
Defining unit tests
Using top-down testing
Testing with specs
Generative testing
Testing with types
Summary
11. Troubleshooting and Best Practices
Debugging your code
Using tracing
Using Spyscope
Logging errors in your application
Thinking in Clojure
Summary
A. References
Index

Mastering Clojure

Copyright © 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: March 2016
Production reference: 1180316
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78588-974-5
www.packtpub.com

Credits

Author
Akhil Wali
Reviewer
Matt Revelle
Commissioning Editor
Neil Alexander
Acquisition Editor
Aaron Lazar
Content Development Editor
Aishwarya Pandere
Technical Editor
Tanmayee Patil
Copy Editor
Merilyn Pereira
Project Coordinator
Nidhi Joshi
Proofreader
Safis Editing
Indexer
Rekha Nair
Graphics
Jason Monteiro
Production Coordinator
Melwyn Dsa
Cover Work
Melwyn D'sa

About the Author

Akhil Wali is a software developer. He has been writing code as a hobbyist since 1997 and professionally since 2010. He completed his post graduation from Santa Clara University in 2010, and he graduated from Visvesvaraya Technological University in 2008. His areas of work include business intelligence systems, ERP systems, search engines, and document collaboration tools. He mostly works with Clojure, JavaScript, and C#. Apart from computers, his interests include soccer, guitar solos, and finding out more about the universe.

About the Reviewer

Matt Revelle is a doctoral candidate in computer science at George Mason University, where he works on machine learning and social network dynamics. He started using Clojure in 2008 and it continues to be his preferred language for many projects and his daily work.

www.PacktPub.com

eBooks, discount offers, and more

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive di...

Table of contents

  1. Mastering Clojure

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.5M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1.5 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access Mastering Clojure by Akhil Wali in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming Languages. We have over 1.5 million books available in our catalogue for you to explore.