Clojure for the Brave and True Learn the Ultimate Language and Become a Better Programmer 1st Edition Daniel Higginbothampdf download
Clojure for the Brave and True Learn the Ultimate Language and Become a Better Programmer 1st Edition Daniel Higginbothampdf download
or textbooks at https://ebookultra.com
https://ebookultra.com/download/clojure-for-the-brave-and-
true-learn-the-ultimate-language-and-become-a-better-
programmer-1st-edition-daniel-higginbotham/
https://ebookultra.com/download/becoming-a-better-programmer-a-
handbook-for-people-who-care-about-code-1st-edition-pete-goodliffe/
Power Chess for Kids Learn How to Think Ahead and Become
One of the Best Players in Your School Charles Hertan
https://ebookultra.com/download/power-chess-for-kids-learn-how-to-
think-ahead-and-become-one-of-the-best-players-in-your-school-charles-
hertan/
https://ebookultra.com/download/the-social-origins-of-language-1st-
edition-daniel-dor/
Trend Trading for a Living Learn the Skills and Gain the
Confidence to Trade for a Living 1st Edition Thomas K.
Carr
https://ebookultra.com/download/trend-trading-for-a-living-learn-the-
skills-and-gain-the-confidence-to-trade-for-a-living-1st-edition-
thomas-k-carr/
The new Atkins for a new you The ultimate diet for
shedding weight and feeling great forever 1st Edition Eric
C.Westman
https://ebookultra.com/download/the-new-atkins-for-a-new-you-the-
ultimate-diet-for-shedding-weight-and-feeling-great-forever-1st-
edition-eric-c-westman/
https://ebookultra.com/download/sigurd-and-his-brave-companions-a-
tale-of-medieval-norway-1st-edition-sigrid-undset/
https://ebookultra.com/download/atomic-scala-learn-programming-in-the-
language-of-the-future-2nd-edition-dianne-marsh/
https://ebookultra.com/download/migration-and-poverty-towards-better-
opportunities-for-the-poor-1st-edition-edmundo-murrugarra/
https://ebookultra.com/download/flickr-mashups-programmer-to-
programmer-1st-edition-david-a-wilkinson/
Clojure for the Brave and True Learn the Ultimate
Language and Become a Better Programmer 1st Edition
Daniel Higginbotham Digital Instant Download
Author(s): Daniel Higginbotham
ISBN(s): 9781593275914, 1593275919
Edition: 1
File Details: PDF, 5.59 MB
Year: 2015
Language: english
Clojure
S h elve i n : P r og r a mmi n g La ng uag e s/Clojure
for The
be united with the programming language you’ve been
longing for: Clojure!
Brave
As a Lisp-style functional programming language, Clojure lets you write robust
The
for
and elegant code, and because it runs on the Java Virtual Machine, you can take
advantage of the vast Java ecosystem. Clojure for the Brave and True offers
a “dessert-first” approach: you’ll start playing with real programs immediately,
as you steadily acclimate to the abstract but powerful features of Lisp and
functional programming. Inside you’ll find an offbeat, practical guide to Clojure,
And
filled with quirky sample programs that catch cheese thieves and track glittery
vampires.
learn h o w to
True
And
• Wield Clojure’s core functions
• Use Emacs for Clojure development
• Write macros to modify Clojure itself
• Use Clojure’s tools to simplify concurrency and parallel programming
Clojure for the Brave and True assumes no prior experience with Clojure, the
language and
Daniel Higginbotham
About t he Au tho r
become a better
Daniel Higginbotham has been a professional programmer for 11 years, half of that at McKinsey &
Company, where he used Clojure to build mobile and web applications. He has also contributed to
the curriculum for ClojureBridge, an organization that offers free, beginner-friendly Clojure workshops
programmer
for women. Daniel blogs about life and programming at http://flyingmachinestudios.com/, and can be
found on Twitter, @nonrecursive. He lives in Durham, North Carolina, with his wife and four cats.
C o v e r s C l o j u r e 1.7
r e q u i r e s J ava 1.6 or l ate r
w w w.nostarch.com
THE FINEST IN
G E E K E N T E R TA I N M E N T ™
Daniel Higginbotham
Clojure for the Brave and True
Clojure for the Brave and True. Copyright © 2015 by Daniel Higginbotham.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval
system, without the prior written permission of the copyright owner and the publisher.
Printed in USA
First printing
19 18 17 16 15 1 2 3 4 5 6 7 8 9
ISBN-10: 1-59327-591-9
ISBN-13: 978-1-59327-591-4
For information on distribution, translations, or bulk sales, please contact No Starch Press, Inc. directly:
Higginbotham, Daniel.
Clojure for the brave and true : learn the ultimate language and become a better programmer / by
Daniel Higginbotham.
pages cm
Includes index.
Summary: "Guide to the functional programming language Clojure. Teaches tools and techniques for
writing programs in Clojure. Covers how to wield and compose Clojure's core functions; use Emacs
for Clojure development; write macros to modify the Clojure programming language; and use Clojure's
tools to simplify concurrency and parallel programming"-- Provided by publisher.
ISBN 978-1-59327-591-4 -- ISBN 1-59327-591-9
1. Clojure (Computer program language) I. Title.
QA76.73.C565H54 2015
005.13'3--dc23
2015014205
No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other
product and company names mentioned herein may be the trademarks of their respective owners. Rather
than use a trademark symbol with every occurrence of a trademarked name, we are using the names only
in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The information in this book is distributed on an “As Is” basis, without warranty. While every precaution
has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any
liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or
indirectly by the information contained in it.
About the Author
Daniel Higginbotham has been a professional programmer for 11 years,
half of that at McKinsey & Company, where he used Clojure to build
mobile and web applications. He has also contributed to the curriculum
for ClojureBridge, an organization that offers free, beginner-friendly
Clojure workshops for women. Daniel blogs about life and program-
ming at http://flyingmachinestudios.com/, and can be found on Twitter,
@nonrecursive. He lives in Durham, North Carolina, with his wife and
four cats.
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
Chapter 10: Clojure Metaphysics: Atoms, Refs, Vars, and Cuddle Zombies . . . . . . . . . . . . 207
Farewell! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
x Brief Contents
Conte nt s in De ta il
Acknowledgments xix
Introduction xxi
Learning a New Programming Language: A Journey Through the Four Labyrinths . . . . . xxii
How This Book Is Organized . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
Part I: Environment Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
Part II: Language Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
Part III: Advanced Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
The Journey Begins! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
2
How to Use Emacs, an Excellent Clojure Editor 11
Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Emacs Escape Hatch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Emacs Buffers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Working with Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Key Bindings and Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Emacs Is a Lisp Interpreter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Installing Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Core Editing Terminology and Key Bindings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Movement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Selection with Regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Killing and the Kill Ring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Editing and Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Using Emacs with Clojure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Fire Up Your REPL! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Interlude: Emacs Windows and Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
A Cornucopia of Useful Key Bindings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
How to Handle Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Paredit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Continue Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3
Do Things: A Clojure Crash Course 35
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Control Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Naming Values with def . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Simplicity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Calling Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Function Calls, Macro Calls, and Special Forms . . . . . . . . . . . . . . . . . . . . . . . 50
Defining Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Anonymous Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Returning Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Pulling It All Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
The Shire’s Next Top Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
let . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Symmetrizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Better Symmetrizer with reduce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Hobbit Violence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
4
Core Functions in Depth 71
Programming to Abstractions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Treating Lists, Vectors, Sets, and Maps as Sequences . . . . . . . . . . . . . . . . . . . 73
first, rest, and cons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Abstraction Through Indirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Seq Function Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
reduce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
take, drop, take-while, and drop-while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
xii Contents in Detail
filter and some . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
sort and sort-by . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
concat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Lazy Seqs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Demonstrating Lazy Seq Efficiency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Infinite Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
The Collection Abstraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
into . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
conj . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Function Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
apply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
partial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
complement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
A Vampire Data Analysis Program for the FWPD . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
5
Functional Programming 97
Pure Functions: What and Why . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Pure Functions Are Referentially Transparent . . . . . . . . . . . . . . . . . . . . . . . . . 98
Pure Functions Have No Side Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Living with Immutable Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Recursion Instead of for/while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Function Composition Instead of Attribute Mutation . . . . . . . . . . . . . . . . . . . 103
Cool Things to Do with Pure Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
comp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
memoize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Peg Thing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Playing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Code Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Creating the Board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Moving Pegs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Rendering and Printing the Board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Player Interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
6
Organizing Your Project: A Librarian’s Tale 125
Your Project as a Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Storing Objects with def . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Creating and Switching to Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
refer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
alias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Real Project Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
The Relationship Between File Paths and Namespace Names . . . . . . . . . . . . 133
Requiring and Using Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
The ns Macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
To Catch a Burglar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Contents in Detail xiii
7
Clojure Alchemy: Reading, Evaluation, and Macros 147
An Overview of Clojure’s Evaluation Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
The Reader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Reader Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
The Evaluator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
These Things Evaluate to Themselves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
Syntactic Abstraction and the -> Macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
8
Writing Macros 165
Macros Are Essential . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Anatomy of a Macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Building Lists for Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Distinguishing Symbols and Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Simple Quoting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Syntax Quoting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Using Syntax Quoting in a Macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Refactoring a Macro and Unquote Splicing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Things to Watch Out For . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Variable Capture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Double Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Macros All the Way Down . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
Brews for the Brave and True . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Validation Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
if-valid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
9
The Sacred Art of Concurrent and
Parallel Programming 189
Concurrency and Parallelism Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Managing Multiple Tasks vs. Executing Tasks Simultaneously . . . . . . . . . . . . . 190
Blocking and Asynchronous Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Concurrent Programming and Parallel Programming . . . . . . . . . . . . . . . . . . . 191
Clojure Implementation: JVM Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
What’s a Thread? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
The Three Goblins: Reference Cells, Mutual Exclusion, and
Dwarven Berserkers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
xiv Contents in Detail
Exploring the Variety of Random
Documents with Different Content
CHAPTER V.
Patrick found that his family had indeed made a happy change.
There was no gainsaying that. And he himself experienced no
difficulty in procuring employment; but he was far from being so well
content as the others. He wrote to Norah upon his arrival at New
York, and again when he had found his father and mother; and he
wanted sadly to invite her to join him in America. But for the same
reason that he did not return to Ireland, he dared not ask her to
come over; for if he could not leave his friends how could she hers?
He would have gone “home,” as he persisted in calling it, but,
strange to say, Ellen was not in the least humbled in her exactions
by the fact of her own marriage. She loved Pat better than any body
in this world, her own husband and her own child not excepted, and
it was with a feeling of wrong that she heard or thought of his loving
any one else, or being beloved by any.
Sad news began now to come from the old country. The O’Brien’s
had no letters; but others had, and the newspapers were full of the
dreadful destitution and the deaths from starvation in Ireland. Now
poor Patrick was worse afflicted than he had been by separation
from his parents. Tidings came of starvation and death in houses the
inhabitants of which he knew were wealthier far than Norah’s father;
and he feared and dreaded that she might even want for a bit of
bread, while he rolled in plenty. Had he pursued his own inclination
he would have posted back—but Ellen said—“Don’t think of such a
thing! Is it mad you are? When there’s people dying there of the
hunger will you go snatch the bread from their mouths? Or will you
go ‘home,’ as you call it, and feed the three kingdoms from your own
pocket?” Patrick was hurt—and he thought of the two Norah was far
the better comforter.
Deep indeed was the distress that rested upon unhappy Ireland.
And Patrick’s fears for his friends at home were but too well
founded. Sickness and famine invaded the district in which Patrick
was born; and though his old master at first was bountiful to those
around him, stern necessity at last brought its admonition that he
must hold his hand. There is distress that opens the heart; but when
it comes to dividing your living with your neighbor, to become at last
fellow in his need, the instinct of self-preservation chills charity.
Nevertheless, the good farmer gave—and gave a day too long; for
the time came when he could count his own scanty provision in food
and in purse. Impoverished, he learned at last to suffer and to
sicken. He buried his wife out of his sight, and his children sunk one
after another into the grave. He denied himself bread to feed his
famishing family—almost rejoicing, while the dead lay unburied in his
house, that with the release of child after child, the need of food and
the wail of hunger diminished. And now at last Norah and himself
only remained of all that happy household; and they had but to
prepare their last food and die. The immense demand which had
been made upon the charitable had proved too great for the supply;
and men had ceased at last to think it a strange thing that people
died of hunger.
Often did Norah think in her distress of him who was now far
away. And heartily she rejoiced for his sake, that he had not
remained to add another claimant on the public charity, to the
thousands who pleaded unavailingly for it. But it was sad to think
that he must one day hear that her he loved had sunk into the
grave, the last of her house, for to death she firmly looked as the
only hope of release from suffering.
A footstep broke the silence; but it hardly disturbed her revery. It
was the kind ecclesiastic who had been present at the death of her
mother and her brothers—who had seen her sister’s eyes closed,
and to whom she herself looked, at no distant day for the last offices
of the church. His frequent visits had become part of her daily
experience, but she saw now that his face wore something more
than the usual calm expression. She looked up inquiringly, and he
placed in her hands a letter, addressed to his care for her.
She knew the handwriting, and could scarce command firmness
to break the many seals and wafers with which over caution had
secured the letter. It was from Patrick, and enclosed more money
than she had before seen for many weeks. “Now, God be praised,”
she cried, “my father shall find comfort again!”
“He has found it, daughter!” said the priest in a solemn voice
from the bedside. Norah hurried there, to receive, in the last faint
smile, a father’s inaudible blessing.
Need we say that the good priest gave Norah sound advice: to
wit, that the money which she had received were better expended in
finding her way to Patrick, than in protracting a weary existence in
the place now so sad to her. Ellen’s welcome was not the least
hearty which Norah received; and all agree that there was a
Providence in the events which guided Patrick before her to America.
Norah is cherished as one of the “childher,” and Mrs. O’Brien insists
that her mistake at the bedside years before, was only a bit of
prophecy, for her heart always yearned to Norah as one of her own.
All are well pleased; and though a shade of sorrow for her kindred is
habitual to the countenance of Mrs. Norah O’Brien, it adds to the
sweetness of its expression, and is a better look, in its resignation,
than one of discontent or of vacuity.
As to the young cousins in the neighborhood, we leave their
statistics to the next census. They have proved jewels of comfort to
Grandfather Patrick, who, though quite infirm, is still useful to “mind
the childer;” while Mrs. O’Brien, the grandmother, labors like
Sisyphus to keep little feet in hose, with no hope that her work will
ever cease while her breath lasts, or her fingers can ply a needle.
A HOUSEHOLD DIRGE.
———
BY R. H. STODDARD.
———
———
BY T. S. ARTHUR
———
——
CHAPTER VI.
Ellison had been in D—— three months, and was about leaving
for Cincinnati, when his lawyer called on him, and stated that he was
authorized by the opposing counsel to say, that the plaintiffs in the
case were willing to withdraw their suit if one hundred acres of the
land in question were relinquished.
“At the same time,” remarked the lawyer, in giving this
information, “it is but right for me to state my belief that the offer
comes as the result of a conviction that the claim urged for the
ownership of the property has no chance of a favorable termination.”
“Yet the suit may be continued for two or three years,” said
Ellison.
“Yes, and they can put you to a great deal of trouble and
expense.”
“And there is at least a doubt resting on the issue.”
“There is upon all legal issues.”
“Then I think we had better accept the compromise.”
“You must decide that for yourself,” said the lawyer.
“How long will the question be open?”
“For some days, I presume.”
“Very well. I will see you about it to-morrow, or at latest on the
day after.”
Clara, on being informed of the new aspect the case had
assumed, fully agreed with her husband that the offer of a
settlement had better be met affirmatively; and this being done, the
suit was withdrawn, and they were left in the peaceable possession
of some four hundred acres of excellent land. The costs were nearly
two hundred dollars. This made it necessary to part with more of
their stock, which was effected through their agent at the East. Five
more shares were sold.
The termination of this suit wrought an entire change in the
views and purposes of Ellison. A residence in the West of three
months had brought him in contact with people of various characters
and pursuits, all eagerly bent on money-making. Towns were
springing up as if by magic, and men not worth a dollar to-day were
counting their thousands to-morrow. The spirit of enterprise was all
around him; and it was hardly possible for him to remain unaffected
by what was in the very atmosphere that he was breathing.
“Let me congratulate you on the happy termination of your suit,”
said an individual with whom Ellison had some acquaintance, a day
or two after all was settled. “You have now as handsome a tract of
land as there is in the state; and if you manage it aright, will make
out of it an independent fortune.”
This language sounded very pleasant in the ears of Ellison.
“You know the tract?” said he.
“Oh yes! Like a book. I’ve traveled over every foot of it. There is
a hundred thousand dollars worth of timber on it.”
“Not so much as that.”
“There is, every dollar of it. Not as fire-wood, of course.”
“In lumber, you mean.”
“Exactly.”
The man’s name was Claxton. He had come to D——, about a
year previously, with some six thousand dollars in cash, and as full of
enterprize and money-loving ambition as a man could well be. The
town was growing fast, and the supply of lumber, which a saw-mill
of very limited capacity was turning out, so poorly met the demand,
that prices ranged exceedingly high. A large landholder, whose
interests were seriously affected by this high rate of lumber, made
Claxton believe that he had only to erect a steam saw-mill, capable
of turning out, per day, a certain number of feet of boards and
scantling, and his fortune was made. Without stopping to investigate
the matter beyond a certain point, and taking nearly all the
statements made by the individual we have named for granted,
Claxton ordered a steam-engine from Pittsburg, rented a lot of
ground on the bank of the river, and forthwith commenced the
erection of his mill. As soon as the citizens of D—— understood what
he was about, there were enough of them to pronounce his scheme
a foolish one, in which he would inevitably lose his money. But he
had made all the calculations—had anticipated, like a wise man, all
the difficulties; and knew, or thought he knew, exactly what he was
about. It was nearly a year before he had his mill ready. By this time
he was not only out of funds, but out of confidence in his scheme for
making a fortune. In attempting to put his mill in operation, some of
the machinery gave way, and the same result happened at the next
trial. Thus expense was added to expense, and delay to delay. In the
mean time, the owner of the other mill had been spurred on by the
approaching competition, to increase its capacity, and was turning
out lumber so fast as to cause a reduction in the price.
So soon as Claxton became aware of the fact that Ellison’s suit
had come to a favorable termination, he conceived the idea of
getting off upon the young artist his bad bargain with as little loss to
himself as possible, and he had this purpose in his mind when he
congratulated him so warmly on his release from the perplexity and
uncertainty of the law.
“Trees standing in the forest, and lumber piled up ready for use
in building,” said Ellison, in reply to Claxton’s suggestion, “are very
different things.”
“Any man knows that. But, in the conversion of the trees into
lumber, lies the means of wealth. There is not an acre of your land
that will not yield sufficient lumber to bring three hundred dollars in
the market.”
“Are you certain of that?” inquired Ellison.
“I know it. The tract is very heavily timbered.”
“Three hundred dollars to the acre,” said Ellison, musing; “four
hundred acres—three times four are twelve. That would make the
lumber on the whole four hundred acres worth over a hundred
thousand dollars!”
“I know it would. And you may rest assured that the estimate is
not high. I only wish I had your chances for a splendid fortune.”
“How is this lumber to be made available?” asked Ellison.
“Cut and manufacture it yourself. You’ll find that a vast deal more
profitable than painting pictures. You can see that this is one of the
best situated towns in the West. The supply of lumber has always
been inadequate for building purposes, and, in consequence, its
prosperity has been retarded. Reduce the price by a full supply, and
houses will go up as by magic, and the value of property rise in all
directions. At present, you could not get over fifteen dollars an acre
for your land if you were to throw it into market. But go to work and
clear it gradually, sawing up the timber into building materials, and,
in ten years, such will be the prosperity of the place, growing out of
the very fact of a full supply of cheap lumber, that every acre will
command fifty dollars.”
The mind of the young man caught eagerly at this suggestion.
He held long interviews with Claxton, who made estimates of various
kinds for him, and gave him mathematics for every thing. They rode
out to the land together, and there it was demonstrated, to a
certainty, that at least seven hundred dollars worth of timber, instead
of three hundred, could be obtained from every acre. Ellison saw
himself worth his hundred thousand dollars, and as happy as such a
realization of his hopes could make him. He went with Claxton to his
mill, where the operation of every thing was fully explained to his
most perfect satisfaction. Even in this enterprise a fortune was to be
made, notwithstanding Claxton had no land of his own heavily
timbered, and would have to pay at least two dollars for every log
brought to his mill, which stood on the river bank. This site had been
chosen because of the facilities it afforded for getting the raw
material which could be floated down from above.
Of all this the young man talked constantly to his wife, and with
a degree of confidence and enthusiasm that half won her cooler and
less sanguine mind over to his views. She did not, however, like
Claxton. Her woman’s true instinct perceived the quality of his mind;
and she therefore had little confidence in him. In suggesting this,
her husband’s reply was,
“I don’t take any thing on his recommendation. I look at facts
and figures, and they cannot lie.”
There was something unanswerable in this; yet it did not satisfy
the mind of Clara.
When Ellison talked to others of what was in his mind, some
listened to what he said in silence; some shrugged their shoulders,
and some said it wouldn’t do. He had been forewarned of this
skepticism by Claxton, and was therefore prepared for it. He well
understood that the people lacked true, far-seeing enterprise; were,
in fact, half asleep! All objections, therefore, that were urged,
rebounded from his mind without producing any rational impression.
He had already picked out a spot for the location of his mill, and
was obtaining estimates for its construction, when Claxton called on
him one day, with a letter in his hand, which he said he had just
received from Cincinnati. It was from a brother who was engaged in
the river trading business, and who owned three large steamboats.
He had already made a fortune. But ill health had come upon him,
and he found it necessary to retire in part from the active duties
which had absorbed his attention for years. To his brother he offered
most tempting inducements to give up his saw-mill scheme, unite
with him, and take the active control of every thing. “If,” said the
letter, “you have any difficulty in finding a person in your stupid
place with enterprise enough to take your mill off of your hands, I
know a man here who will relieve you; but he will want time on
nearly the whole amount of the purchase. He is perfectly safe,
however, possessing a large amount of property.”
Of course, Mr. Claxton, having taken a particular fancy to Ellison,
and being anxious to put him fairly in the road to fortune, offered
him the mill at cost; and Ellison, without asking the advice of any
one—being fully impressed with the belief that he knew his own
business, and had sense enough to understand a plain proposition
when presented, immediately closed with the offer. The price asked
was exactly cost, and to determine what this was, the bills for every
thing were exhibited and taken as the basis of valuation. According
to these the mill had cost six thousand dollars. And for this sum,
Claxton generously consented to sell the entire concern, with all
prospective benefits, to his young friend. The amount of cash to be
paid down was three thousand dollars, and for the balance, notes of
six, nine, and twelve months were to be given, secured by mortgage
on the four hundred acres of land.
When matters assumed this aspect, Clara, who, strangely enough
to the mind of Alfred, appeared to like Claxton less and less every
day, suggested many doubts, and proposed that the matter should
be submitted to three old residents of the place, and their advice
taken as conclusive. But Alfred objected to this. They were plodders,
he said, in an old beaten track, where, like horses in a mill, they had
gone round and round until they were blind. They would, of course,
suggest a thousand doubts and difficulties, all of which he had
already solved. There was no aspect of the case in which he had not
viewed it, and he understood all the bearings better than any one
else.
“He is a poor sort of a man who cannot lay his course in life, and
steer safely by force of his own intelligence,” said the young man,
proudly.
Clara, however, was not satisfied; but having had some
experience in regard to her husband’s sensitiveness when any
question touching their property came up, she was afraid to say a
great deal in opposition to a purpose that was so fully formed as to
admit of no check without painful disturbance. So she permitted him
to take his own way, neither approving nor objecting.
Alfred understood, however, from his wife’s manner, that she had
little confidence in the new business upon which he was about
entering.
“Happily, I will disappoint her fears,” was his consoling and
strengthening reflection. “When her little property has swelled in
value to fifty or sixty thousand dollars, how different will be her
feelings! She will then understand the character of her husband
better—will know that he is no common man.”
With a presentiment of coming trouble, Clara saw their stock
sold, and three thousand dollars paid over to Claxton; but she
appeared to acquiesce in the transaction so entirely, that Alfred was
deceived as to her real feelings.
[To be continued.
THE PRIZE SECURED.
Engraved expressly for Graham’s Magazine
THE PIRATE.
———
BY HENRY B. HIRST.
———
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookultra.com