Learn You Some Erlang for Great Good A Beginner s Guide 1st Edition Hebert instant download
Learn You Some Erlang for Great Good A Beginner s Guide 1st Edition Hebert instant download
https://ebookmeta.com/product/learn-you-some-erlang-for-great-
good-a-beginner-s-guide-1st-edition-hebert/
https://ebookmeta.com/product/property-based-testing-with-proper-
erlang-and-elixir-1st-edition-fred-hebert/
https://ebookmeta.com/product/you-are-a-great-and-powerful-
wizard-self-care-magic-for-modern-mortals-good-life-sage-liskey/
https://ebookmeta.com/product/understanding-blockchain-
technology-a-beginner-s-guide-1st-edition-digitalmadic-com/
https://ebookmeta.com/product/introduction-to-food-chemistry-1st-
edition-vassilis-kontogiorgos/
A Life of Sir Harry Parkes British Minister to Japan
China and Korea 1865 1885 1st Edition Robert Morton
https://ebookmeta.com/product/a-life-of-sir-harry-parkes-british-
minister-to-japan-china-and-korea-1865-1885-1st-edition-robert-
morton/
https://ebookmeta.com/product/mind-bomb-1st-edition-don-
pendleton/
https://ebookmeta.com/product/principles-of-pharmacology-4th-
edition-h-l-sharma/
https://ebookmeta.com/product/premodern-beliefs-and-witch-trials-
in-a-swedish-province-1669-1672-1st-edition-goran-malmstedt/
https://ebookmeta.com/product/dough-shall-not-murder-vy-creek-
cozy-mystery-8-1st-edition-ruth-baker/
SCHWESERNOTES 2023 LEVEL II CFA BOOK 4 FIXED INCOME
DERIVATIVES AND ALTERNATIVE INVESTMENTS 1st Edition
Kaplan Schweser
https://ebookmeta.com/product/schwesernotes-2023-level-ii-cfa-
book-4-fixed-income-derivatives-and-alternative-investments-1st-
edition-kaplan-schweser/
Learn You Some Erlang
for Great Good!
You Some Erlang for
ang LearnGreat
for You SomeGood !
A Beginner’s Guide
at Good Erlang ! for
ginner’s Great
Guide Good!
A Beginner’s Guide
Fred Hébert
Foreword by Joe Armstrong
Fred Hébert
word by Joe Armstrong
San Francisco
Fred Hébert
Foreword by Joe Armstrong
Learn You Some Erlang for Great Good! Copyright © 2013 by Fred Hébert.
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
17 16 15 14 13 1 2 3 4 5 6 7 8 9
ISBN-10: 1-59327-435-1
ISBN-13: 978-1-59327-435-1
For information on book distributors or translations, please contact No Starch Press, Inc. directly:
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 infor-
mation contained in it.
Brief Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Chapter 2: Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Chapter 25: Bears, ETS, Beets: In-Memory NoSQL for Free! . . . . . . . . . . . . . . . . . . . . . . . 419
Afterword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 581
vi Brief Contents
Conte nt s in De ta il
Preface xxi
To the Foreigner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
To the Erlang Regular . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
To the Person Who Has Read This Online . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
Acknowledgments xxiii
Introduction 1
So What’s Erlang? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Don’t Drink Too Much Kool-Aid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
What You Need to Dive In . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Where to Get Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1
Starting Out 7
Using the Erlang Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Entering Shell Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Exiting the Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Some Erlang Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Invariable Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Atoms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Boolean Algebra and Comparison Operators . . . . . . . . . . . . . . . . . . . . . . . . 14
Tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
List Comprehensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Working with Binary Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Bit Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Bitwise Binary Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Binary Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Binary Comprehensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2
Modules 31
What Are Modules? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Creating Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Compiling Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Compiler Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Defining Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
More About Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Circular Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3
Syntax in Functions 43
Pattern Matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Fancier Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Variables in a Bind . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Guards, Guards! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
What the If ?! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
In case ... of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Which Should We Use? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
4
Types (or Lack Thereof) 55
Dynamite-Strong Typing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Type Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
To Guard a Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
For Type Junkies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5
Hello Recursion! 61
How Recursion Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Length of a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Length of a Tail Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
More Recursive Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
A Duplicate Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
A Reverse Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
A Sublist Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
A Zip Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Quick, Sort! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
More Than Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Thinking Recursively . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
6
Higher-Order Functions 77
Let’s Get Functional . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Anonymous Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
More Anonymous Function Power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Function Scope and Closures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Maps, Filters, Folds, and More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Fold Everything . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
More Abstractions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
8
Functionally Solving Problems 105
Reverse Polish Notation Calculator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
How RPN Calculators Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Creating an RPN Calculator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Testing the Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Heathrow to London . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Solving the Problem Recursively . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Writing the Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Running the Program Without the Erlang Shell . . . . . . . . . . . . . . . . . . . . . . . 118
9
A Short Visit to Common Data Structures 121
Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Defining Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Reading Values from Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Updating Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Sharing Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Key/Value Stores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Stores for Small Amounts of Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Larger Dictionaries: Dicts and GB Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
A Set of Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Directed Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Queues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
End of the Short Visit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
10
The Hitchhiker’s Guide to Concurrency 135
Don’t Panic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Concurrency Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Scalability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Contents in Detail ix
Fault Tolerance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Concurrency Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Not Entirely Unlike Linear Scaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
So Long and Thanks for All the Fish! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Spawning Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Sending Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Receiving Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
11
More on Multiprocessing 149
State Your State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
We Love Messages, But We Keep Them Secret . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Time Out . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Selective Receives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
The Pitfalls of Selective Receives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
More Mailbox Pitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
12
Errors and Processes 161
Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
It’s a Trap! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Old Exceptions, New Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Monitors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Naming Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
13
Designing a Concurrent Application 175
Understanding the Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Defining the Protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Lay Them Foundations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
An Event Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Events and Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Adding An Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
The Event Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Handling Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Hot Code Loving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
I Said, Hide Your Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
A Test Drive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Adding Supervision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Namespaces (or Lack Thereof) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
14
An Introduction to OTP 199
The Common Process, Abstracted . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
The Basic Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Introducing the Kitty Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Generalizing Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
x Contents in Detail
Generalizing the Server Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Starter Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
Generalizing Kitty Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Specific vs. Generic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Callback to the Future . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
The init Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
The handle_call Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
The handle_cast Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
The handle_info Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
The terminate Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
The code_change Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
.BEAM Me Up, Scotty! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
15
Rage Against the Finite-State Machines 219
What Is a Finite-State Machine? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Generic Finite-State Machines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
The init Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
The StateName Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
The handle_event Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
The handle_sync_event Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
The code_change and terminate Functions . . . . . . . . . . . . . . . . . . . . . . . . . 225
A Trading System Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Show Me Your Moves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Defining the State Diagrams and Transitions . . . . . . . . . . . . . . . . . . . . . . . . 227
Game Trading Between Two Players . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
The Public Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
FSM-to-FSM Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
The gen_fsm Callbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
That Was Really Something . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Fit for the Real World? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
16
Event Handlers 247
Handle This! *pumps shotgun* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
Generic Event Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
The init and terminate Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
The handle_event Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
The handle_call Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
The handle_info Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
The code_change Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
It’s Curling Time! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
The Scoreboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
Game Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
Alert the Press! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Contents in Detail xi
17
Who Supervises the Supervisors? 263
Supervisor Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
Using Supervisors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Restart Strategies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Restart Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
Child Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
Band Practice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
Musicians . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
Band Supervisor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Dynamic Supervision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
Using Standard Supervisors Dynamically . . . . . . . . . . . . . . . . . . . . . . . . . . 277
Using a simple_one_for_one Supervisor . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
18
Building an Application 281
A Pool of Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
The Onion Layer Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
A Pool’s Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
Implementing the Supervisors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
Working on the Workers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Writing a Worker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
Run Pool Run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Cleaning the Pool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
19
Building Applications the OTP Way 303
My Other Car Is a Pool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
The Application Resource File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
Converting the Pool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
The Application Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
From Chaos to Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
Library Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
20
The Count of Applications 315
From OTP Application to Real Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
The Application File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
The Application Callback Module and Supervisor . . . . . . . . . . . . . . . . . . . . 318
The Dispatcher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
The Counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
Run App Run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
Included Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
Complex Terminations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
22
Leveling Up in the Process Quest 353
The Hiccups of Appups and Relups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
The Ninth Circle of Erl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
Process Quest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
The regis-1.0.0 Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
The processquest-1.0.0 Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
The sockserv-1.0.0 Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360
The Release . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360
Making Process Quest Better . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
Updating code_change Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
Adding Appup Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Upgrading the Release . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
Relup Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
23
Buckets of Sockets 375
IO Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
UDP and TCP: Bro-tocols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
UDP Sockets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
TCP Sockets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
More Control with Inet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
Sockserv, Revisited . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
Where to Go from Here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396
24
EUnited Nations Council 397
EUnit—What’s an EUnit? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
Test Generators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
Fixtures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
More Test Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
Test Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
Testing Regis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408
He Who Knits EUnits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
"I have had all the rooms above stairs well examined," replied the
Count of Ehrenstein, thoughtfully; "except, indeed, your own, my
noble friend; and there I did not dream that any one could be
concealed. The mystery is, how these doors have been opened, the
fugitives brought forth, and all made fast again. That there is
treachery somewhere, no one can doubt; and those who released
them from confinement would doubtless assist them in flight."
"Nay, not so," replied the jester, "but he told me that it led to
vaults, and to the serfs' burial-place,--very awful vaults, indeed, my
noble lord, where nobody would venture; and he hinted how terrible
deeds had been done there, which had begotten many ghosts. I am
not sure he did not speak of devils too; but he was marvellous
conversant with all that the place contained; and his was a bold
heart, just fit to trust himself with spirits, good or bad."
"Come," cried the Count hastily, "we will search;" but he led the
way from the door which had been the theme of the jester's
conversation, and, followed by several attendants, examined
carefully every part of the building which had not been searched
before, till he came to the door of the great hall again; but there he
paused, and seemed unwilling to go farther.
"Let us on, Ehrenstein," said Count Frederick, "and make the work
complete by looking through these vaults."
"They are not there," answered the Count, in a hesitating tone; "I
feel sure they would not venture."
Henry of Geisen was ready to go wherever his lord went, and Fritz
Munter would go wherever Henry of Geisen turned his steps. Two or
three more were collected, who, though it cannot be said they
showed no fear--for every one looked somewhat dull when the
vaults were mentioned--did not hang back; and torches being
procured, the Count of Ehrenstein, with a heavy brow and teeth
hard set, approached the little door on the left of the dais. It was
fixed as firm, however, as a piece of the wall, and did not seem to
have been opened for years.
"Stay," said the Count, who, having made his mind up to the
examination, would not now be disappointed; "I will bring the keys."
"That is mine," cried the jester, setting his broad square cut shoe
upon it. "I defy you to match that for a neat, tiny, little foot, in all
the castle."
But the very fact of a footmark being so near the door confirmed
the Count in his resolution of going on; and after some trouble, for
the key was rusty with neglect, the door was opened, and a torch
held up to light the way. On the whole party went, along the stone
passage, down the well stairs, and then into the vault; but here it
seemed as if all the noxious beasts of the place had leagued
together to oppose their passage. Hundreds of bats flapped through
the air, and, dazzled by the torches, swept close past the faces of
the intruders; enormous toads, bloated and slow, crept across the
ground; two or three large snakes darted away, hissing and showing
their forked tongues; long earth-worms, and hideous orange slugs,
wriggled or crawled along the path; and a large mole cricket dashed
itself in the eyes of one of the men, making him start back in terror.
"Now," he cried, "if they are here, we have them safe;" and he
then applied himself to make his companions spread out and sweep
the whole width of the vaults on the way back, so that the torches
might light every part of the space--he himself keeping on the
extreme right. But this he found difficult to accomplish: the men
loved not to be separated; and only Count Frederick and the jester
would take the places assigned to them,--the others keeping close
together, and following one or other of the three. The torch-light,
too, lost itself in the old darkness of the place, as soon as, having
quitted the crypt, where the windows afforded some light, however
dim, they entered the wider vaults where the serfs were buried; and
often one person stopped, or another, as they went along,
examining the various objects that met their eyes. The Count of
Ehrenstein himself paused at a door on his right, and looked to
ascertain that it was fastened; but he soon resumed his advance
again, and had nearly reached the other side, when a voice, loud
and commanding, suddenly cried, "Stand!"
Every one started, and there was a dead silence for an instant.
"Not I," exclaimed Count Frederick. "It seemed to come from your
side."
"I heard it on both sides," said the jester; "but that is natural,
having two ears."
The men crowded up to the spot where the nobleman stood. The
Count of Ehrenstein came more slowly; but when he did come, he
found his friend gazing at the skeleton chained to the stone column.
That, however, was not the only object that met his eyes; for in the
bony hand was a long strip of vellum, falling almost to the ground,
and upon it in large characters, written apparently in blood, was the
word "Vengeance!"
The Count paused, and gazed with his eyes straining from their
sockets, his mouth half open, and his nostrils expanded; while
beside him stood Count Frederick, and behind, the jester, with his
eyes bent upon his lord's entertainer, his lip quivering, and his brow
knit into a dark and ominous frown. All kept silent for some time,
and no one moved, unless indeed it was the jester, whose hand
opened and shut more than once upon the hilt of his dagger. At
length Count Frederick broke the terrible silence, and inquired,
"What is this, Ehrenstein?"
CHAPTER XXXIV.
"Halt!" cried, at length, the same voice which had more than once
sounded in the ear of Ferdinand of Altenburg, during the eventful
night of his escape from the castle of Ehrenstein, but now speaking
in a louder tone than before; and the hands which still held the arms
of the young fugitive somewhat relaxed their grasp. Ferdinand,
however, had now a more definite idea of the place to which he had
been brought; for during the time they had paused in the wood, and
the half hour which had elapsed since they had resumed their rapid
course, he had had time to collect his thoughts, which at first were
confused with agitation and excitement. As soon as they began to
move, he had perceived that they rapidly descended the hill; and
shortly after, though the cowl was far over his eyes, he caught the
glistening of the river at a few steps' distance. The next minute it
became clear that they were passing over the bridge; and then they
threaded tortuous ways, narrow and overgrown with briars and
weeds, which, he was sure, could only lead to the old castle on the
hill opposite to Ehrenstein.
When, at length, the voice cried "Halt!" as I have said, the young
gentleman felt sure that they must be standing in one of the grass-
grown courts or ruined halls of the dilapidated building. The
stamping noise of tethered and impatient horses, too, was heard;
and many whisperings, as of a number of men speaking in low
tones, sounded around. All was as dark as the pit of Acheron,
however; till suddenly a dull red glare found its way even under the
cowl; and, a minute after, the same voice said aloud, "Bring him
forward; leave the other--he is safe; but bring the last before me."
But, the instant after, a figure was brought forward before the
seated leader, which at once arrested all Ferdinand's attention; for at
a glance he recognised the Baron of Eppenfeld.
Even now, though the scene and the circumstances were well
calculated to strike terror even into a bold and resolute heart, the
Baron maintained his air of rude and reckless daring, gazed round
the groups in his neighbourhood, fixed his eyes upon the principal
figure, looked at the swordsman with his naked weapon, and then,
with a laugh, exclaimed, "Well, I am amongst comrades, it seems.
We are all of a feather, doubtless, though I knew not there were so
many eagles within a day's flight of my own eyry."
"Eagles, kite!" exclaimed the voice of the gigantic figure with the
black plume. "You merit plucking for your insolence in comparing a
carrion fowl like thyself to noble birds. Listen, Baron of Eppenfeld,
and answer before the court of the Black Rider; and mark well all
that thou seest, and all that thou hearest. Look at that sword."
"I see it," answered the Baron; "it is long and strong, and in a
good hand may do good service."
"The edge is sharp," replied the voice; "and ere half an hour be
over that edge shall smite thy neck, if thou answerest not, or
answerest untruly, any question that is asked."
But the tone of him who spoke speedily removed all doubts.
"Well, then," said the voice, "be it as you say. Kneel down, Baron of
Eppenfeld.--Strike off his head,--but, first, smite the spurs from the
heels of the felon!"
Before the Baron could turn round, or had time to say another
word, the blow of an axe from some one behind struck away the
marks of knighthood from his heels, the sharpest indignity that man
could suffer in those days; and, while his heart beat, and his cheek
grew red and white, the voice again exclaimed, "Kneel down!"
"Stay, stay," cried the Baron, now convinced that it was no jest
they practised on him. "What are your questions?"
"Live, to be sure," cried the Baron. "Think you I would die while
grapes grow beside the Rhine, or the roe deer bounds upon the
mountain? Ask what you will, I will answer."
"Speak without pause or hesitation, then," said the Black Rider. "If
he falter but at a word, sweep off his head. Now, mark well! Did the
Count of Ehrenstein, some sixteen years ago, send you with your
men to seize, near Ulm, a lady and her child?"
"He did," replied the Baron; "but 'tis well nigh seventeen years, I
think."
"Did he give you a bond for the payment, in three years, of two
thousand ducats for the deed?" asked the voice.
"Ay, did he; and he paid all but two hundred ducats," answered
the Baron; "that, he would not pay till I proved that I had done all
that he required."
"What more did he require than their mere seizure?" inquired the
voice.
"Two days ago, I could have said Yes," was the Baron's answer;
"but they have sacked and razed my castle, and all the papers--for
there were letters many--have either been taken or burnt."
"Now, speak the truth," said the Black Rider; "Who has the
papers?"
"What became of the child and the mother?" asked the voice
again.
"I cannot tell," replied the captive. "They had received timely
notice, it would seem, of my errand, and had fled ere I reached Ulm;
but I have heard that both died of the fever at Regensburg, not a
year after. It is true, too; for those who told me knew what they
said. So I swore to the Count that they were dead; but because I
could bring no one to prove that they perished in the Danube, he
would not pay the rest, and I kept the bond."
"Who read to you the Count's letters, and wrote your answers,"
inquired his interrogator; "for you are no clerk yourself?"
"A shaveling--a priest I had with me then," said the Baron. "He
had fled to me from Würtzburg, where he had killed a man in a fray
about a woman; but he is dead now, the good clerk. He drank half a
hogshead of red wine in a week, which made him so sleepy he never
woke again."
"No more of him," cried the voice sternly. "So the mother and the
child died of the fever. Now, speak; Who were they?"
"Nay, that I know not," said the prisoner. "All I know is what the
Count told me, which was, that she was his dead brother's leman,
and the boy a bastard, whom he did not believe even to be his
brother's child. They wanted money from him, I fancy, on some old
written promise of the last count--a thousand Venetian ducats
yearly--so he told me; and he thought it best to give me two years
of the payment, and have done with it for ever."
"Is this all you know of this matter?" asked the Black Rider again.
"All, upon my life!" answered the Baron. "They are both dead--
that is certain; but I had no hand in their death, I will swear upon
the holy cross." The gigantic figure remained motionless and silent
for more than a minute, then waved his hand from right to left with
a peculiar motion. The Baron turned his head, in some doubt
whether he should not see the naked sword behind him taking the
same direction towards his neck; but suddenly the man who held the
torch reversed it, pressed the flaming end upon the ground and the
next moment all was darkness.
"Go on, and mount," said the voice, in the same low tone.
CHAPTER XXXV.
Adelaide was sad, though the words of the priest had, in some
degree, allayed the anxiety she felt for him she loved; but yet she
was sad--very sad. There were now other causes of depression
weighing down her mind, which during the fever of apprehension
she had not experienced. She now felt what it was to quit her
father's house, a fugitive--under his anger--under, perhaps, his
curse. There might indeed be matter of consolation in her thoughts;
there might be a full justification of her conduct to her own heart.
She might feel, or might believe, that she had done no wrong.
Scanning her motives as severely as she could, she might, with a
clear conscience, say, that not for any personal feeling,--not for love,
or from weakness, had she neglected a duty to a parent; that
passion, or fancy, or attachment, had not shared, even in a degree,
in what she had done. Though she loved as deeply as she was loved
in return, and owned to her own heart that she had made no
sacrifice of aught but the girl's timidity, still it was sad to quit the
home of youth as an outcast. It weighed upon her that her father's
last words to her should have been those of anger and bitterness;
that the eye which had ever looked beaming upon her, even when it
fell cold and harsh on others, should at length have blazed with rage
as it rested on her face.
She felt very sad then: she could take no pleasure in the scenes
through which she passed, though the green woods were
everywhere pleasant to the eye, and often many a lovely spot
peeped in upon her through the sloping chasms in the hills, as she
went along. In vain Bertha, with gay talk, strove hard to win her
from her heavy thoughts; and though the men who accompanied
her were kind and civil in their rude way, yet nought could win a
smile to poor Adelaide's lip.
The sun rose high, and looked down into the dells through which
they wound along, gilding the banks of moss, and chequering the
narrow road with waving filigree work, of yellow light and green
shade. He began to sink behind the branches of the higher trees,
and a cool, fresh air followed his decline. Through the most
unfrequented parts of the wide forest, which stretched far along the
hills, they took their way, avoiding village, and hamlet, and farm,
and even keeping at a distance from the course of the stream. The
paths they chose were those of the woodman; or the hunter; but
even the latter trod them so seldom, that more than once, from a
thicket close at hand, the wild roe bounded away; and twice or
thrice, where a shady glade opened into the heart of the wood, a
stag was seen raising his antlered head, and gazing steadfastly at
the unwonted sight of a cavalcade crossing his own habitual
solitude.
At length, after four hours' slow riding, the man who seemed the
leader of the little troop which had been sent to guard Adelaide on
her way, drew in his horse, saying, "I think, lady, we must now be
beyond all danger, and can well afford to halt for an hour to refresh
ourselves and our horses, under the trees, with the provisions which
my lord, the Abbot, has bountifully supplied."
"If the horses need refreshment, let us stop," replied Adelaide: "I
would not have the poor beasts misused for me; but you need not
halt on my account: I do not need any repose, and am only anxious
to proceed as fast as may be."
The good man, however, chose to take it for granted that the
cattle did want food and rest, though they had fed well at the abbey,
and had rested for some hours. Bertha, too, to say the truth, was
right glad of some refreshment; for she had had a weary and an
apprehensive night; and hers was a light heart, that forgot its fears
as soon as danger was no longer very apparent.
The sun where they sat was shining brightly upon a small open
space in front, not a cloud seemed to shadow any part of the sky,
and the tops of the distant hills, seen through the brake, appeared
peculiarly sharp and clear. But, in the midst of this serenity,
Adelaide's quick ear caught a peculiar rolling sound, coming
apparently from a distance on the right, and starting up, she asked,
"Is not that thunder?" adding, "let us go on quickly, I pray you, Sir."
"Oh, 'twas but the wind amongst the trees, lady," answered the
man, hardly moving a limb: but his assertion was contradicted a
moment after by a louder and a nearer peal.
All was now bustle and hurry. The horses were prepared in haste,
the remnants of the meal packed up, and the whole party mounted.
But scarcely had Adelaide advanced a hundred yards, when a bright
flash broke across the path; and, ere she had gone half a mile, the
rain poured down in torrents. The leader of her little troop was now
really kind: often and anxiously he looked back towards her; would
fain have stripped himself of his cloak to defend her better from the
large, heavy drops that, as they fell, went through and through the
gown of black serge which she wore above her ordinary dress; and
sent two men away, to the right and left, to see if they could find
any cottage, or woodman's hut, which would afford a covering from
the storm. A shed was at length discovered, and there two weary
hours were passed, till the lady declared, looking up to the sky, that
she would rather proceed, notwithstanding the continued rain, than
delay her journey longer. The leader of the troop was not unwilling,
and, after a short pause, they again began their march, and
proceeded for a mile, or somewhat more, uninterrupted. The rain
still poured upon their heads, and, far from affording any shelter, the
trees seemed but to collect the water amongst the branches, and
then let it fall in larger drops upon the travellers as they passed. But
at length they seemed to approach the verge of the wood; for,
through the avenue of tall beeches which they were now pursuing,
Adelaide could see an open field of green corn, with some shrubs
and scattered brushwood beyond again, though the grey film of
heavy drops, which hung like a thin curtain over all the distant
objects, prevented her from distinguishing anything clearly. It was
evident, however, that the leader of the band thought they were
approaching a point of some danger; for he sent on one of his
horsemen a little in advance, to reconnoitre the ground, and
followed more slowly, as if unwilling to advance till he had received
intelligence. The man returned in a minute at full speed, and said
something, in a low tone, which the lady did not distinctly hear.
Instantly, however, the leader turned to her, exclaiming, "Ride back,
lady, with your woman. There are armed men in front, who, he
thinks, have seen him: ride back to the shed. We will--"
But, ere he could finish his sentence, or Adelaide could ask any
questions, there was the sound of many horses' feet beating the
plashy ground at a quick pace; and, looking between the shoulders
of the horsemen who were in front, the lady saw a number of
mounted men coming rapidly down the road. All was, in a minute,
confusion and bustle: Adelaide's male companions hastening to
spread out across the road before her, at once to conceal her flight
and to prevent pursuit. Without waiting to see more, she drew her
rein in terror, and urging her horse into its quickest pace, dashed
away till she reached the narrow turning which led to the small
woodman's shed, up which she instantly directed her course, nor
stopped till she saw the rough hut, with its thatched roof raised
upon six bare poles. There, however, she paused, and looked
behind, thinking that Bertha was following; but the girl was not to be
seen.
The lady listened; but for a moment no sound was heard: then
the quick trampling of horses' feet reached her ear; and Adelaide
fancied that Bertha was coming; but the beasts and their riders
passed by the end of the little path,--at least she believed that they
must have done so, for no one appeared, and the sounds grew
gradually fainter and more faint, till at length they died away. The
poor girl's heart sank. What had become of her companions? she
thought; what had become of Bertha? Had they met with her
father's soldiery, and been routed and driven back? and was she left
there, in the midst of the wood, alone, and without help or
guidance? Every fearful image that fancy could call up presented
itself to her mind; and, though Adelaide was not faint-hearted, yet,
for a time, her courage failed at the thought of all that might occur
to her under such circumstances. She struggled against her terrors,
indeed,--she would not dwell upon the dangers; and she was
nerving her mind to consider calmly what it was best for her to do,
when again the trampling sound of horse was heard; and, leaving
the beast that bore her, under the woodman's shed, she drew back
amongst the trees, and listened. The next moment a loud voice
exclaimed, as if shouting to some distant companions, "Here; the
hoofs have turned up here. Come on, come on!"
It was evidently not one of the party which had accompanied her
from the abbey who was now seeking her, for they knew whither she
had gone; and the lady drew further back, still hiding herself
amongst the wet trees and bushes, yet leaving herself just room to
see what passed on the open spot around the shed. The boughs had
hardly ceased waving where she had pushed them aside, when, first
a single soldier, leading his horse by the bridle, appeared, and then
two or three others, mounted. Their faces were strange to her; they
were none of the men of Ehrenstein; but that they were seeking her,
soon seemed clear, for one of them exclaimed, "Ah, here's the girl's
horse--take care; don't frighten it;" and, bending down low, behind
the bushes, Adelaide remained as still as death; but with a beating
heart. What more was said she did not hear, though the men
remained some time, and seemed to converse eagerly: but that
which appeared most strange was, that, as far as she could see,
they made no attempt to search the copses around; and at length,
mounting their horses again, rode quietly, but quickly, away.
For several minutes, she did not venture to raise her head; but
when at length she did so, and looked towards the shed, she saw
that the jennet which had brought her thither was gone. At first her
brain seemed to swim with terror, and her knees shook violently.
Alone, in a part of the country which she did not know, without any
means of proceeding but such as her own weary and trembling
limbs afforded--surrounded, perhaps, by those who were seeking to
carry her to an imprisonment which would almost be worse than
death--or in the midst of wild, lawless bands, which were but too
numerous in those days,--with night fast approaching, and no
shelter near but the wide wood, what was she to do?--whither was
she to go?--where could she find refuge?
"I will wait," she said, at length, "till night begins to fall, and then
quietly find my way forward, and seek out the peasant's dwelling
who has tilled those fields. Though rude, the boors are kind-hearted;
and I am sure they will give me shelter for the night, and, perhaps,
help me on my way to-morrow."
She resolved to do so; and rising, she crept back to the small path
that led from the woodman's shed to the wider road which she had
lately been travelling, and then gazed along it as far as the eye could
reach. Nothing was visible; though in the cool evening light, with the
sun just upon the horizon, shining out from beneath the exhausted
clouds, she could see clearly as far as a spot about two hundred
yards in advance, where the path, taking a turn, was lost amongst
the trees. With a cautious step she went on, pausing to listen every
minute, till she gained a sight of the continuation of the little way. All
was still clear; but yet she feared to trust herself in the wider road,
which she could now perceive crossing the path she was following;
and, drawing somewhat back behind an oak, she watched eagerly
for a moment or two, while the sun sank, the rosy light that tinged
the clouds overhead died away, and the grey shadow of the coming
night was cast upon the earth.
"I must go on," she said to herself; but still she dreaded to do so,
and did not move, till suddenly a tall hart came slowly trotting down
the road, passed the end of the path in which she was, after
standing for a moment to gaze, as if considering which way he
should take, and disappeared in the very direction in which she was
proceeding.
Without further hesitation she went upon her way, turned up the
road to the right, and followed it quickly, for the light was failing
fast. Night had completely closed in ere the trees ended; and she
found herself standing by a field of green corn, with what seemed a
little patch of vineyard on a slope beyond, and a dim line of trees
farther forward still. The stars were out in the sky above, for by this
time the stormy clouds had cleared away; but there was, in the
scene, a pleasanter light to the eye of the poor wanderer, than even
the twinkling lamps of heaven. At some distance to the right, were
seen a number of what she concluded were cottage windows, with
rays, as if from fires or candles within, streaming forth upon the
darkness; and, at her side, she saw the commencement of a path,
apparently leading, to the village or hamlet.
She was very weary; but that sight gave her strength; and, with a
quickened pace, she hurried on. The lights grew more distinct as she
advanced, and she caught a faint glimpse of the buildings before
her. There were cottages, evidently, and a little church; but a larger
and more imposing edifice appeared on the left. It might be a
stronghold--it might be a monastery or convent; and Adelaide tried
to recollect all she had heard of the places in the neighbourhood, in
order to divine what the building could be that now rose before her
eyes, towering higher over the trees every step, as she came nearer.
She knew not, however, how far she had gone, or what direction she
had taken, and she only puzzled herself with conjectures, till she
arrived at the first house of the village, which stood a little in
advance of those tall walls, from which no light proceeded. From two
windows of the lesser building, indeed, the friendly rays were
streaming plentifully; and Adelaide determined to pause there, and
ask for shelter; but she found some difficulty in approaching it. It
was a small house, within a garden, apparently neither the cottage
of a peasant, nor the dwelling of a farmer; for there was a low wall
round the garden, and that wall, again, was surrounded by a foss,
full of water. It did not seem, indeed, defensible against any large
force; but it was, at all events, guarded against the sudden attack of
maurauders; and Adelaide thought she could see the wall winding
along till it joined that of the larger building behind. On the side next
to her she could find no entrance, nor any means of passing the
moat; but when she had walked on, round the angle of the wall,
there appeared a little wooden bridge, and a door, with the masonry
raised several feet on either side, so that no one approaching by the
bridge could leap over into the garden. By the side of the door was
the large iron pulley of a bell; but the young wanderer paused,
doubting whether she should ring there, or go on to one of the
cottages a little further up the hill. She was very weary, however;
her limbs felt powerless; her heart was faint; and with a feeling like
despair, she put forth her hand and rang the bell.
The next minute she heard a door open within the enclosure, and
a step cross the garden. Then a wooden shutter was drawn back
from before a small aperture in the gate, barred with iron; and a
voice asked, "Who is there?"
"I have lost my way in the wood," she replied, "and have suffered
much. I am wet, weary, and faint, and I pray you give me shelter for
the night, in Our Lady's name."
"Quite," answered the lady: "I was not alone in truth, for I had
some men from the abbey of--" She paused, and omitting the name,
went on--"from the abbey, with me and my maid; but we were met
by an armed band, who attacked us, and I fled. Since then I have
wandered on, and know not where I am."
CHAPTER XXXVI.
"Your steps totter, poor child," said the woman who opened the
gate to Adelaide; "here, lean upon my arm; but first let me make
fast the door. We live in strange bad times; but here you will be safe,
if there is safety to be found; for no one will venture to assail the
Convent of the Holy Cross, or those who live beneath its walls."
Adelaide made no reply; for there are moments when the motives
for exertion having ceased, the very relief from terror and anxiety is
in itself overpowering, and the corporeal frame yields at the instant
of deliverance to the weight it had borne up under during the period
of peril. She perceived by a faint light, which streamed from the half
open door of the house, that the person who spoke to her was not
habited in the garb of a nun, although she mentioned the convent as
her assurance of security; but Adelaide could ask no question, make
no reply. Everything seemed indistinct and misty; the gardens, with
the rays from the windows and the door pouring in long lines
through the green leaves of the vine, swam before her eyes; her
limbs lost their power, her tongue clove to her mouth, and it was
with difficulty that, aided even by the woman's arm, she reached the
threshold of the house. Her companion pushed the door further
open; and supported her up the little step, but at the top the poor
girl leaned more heavily still upon her guide's arm, and the next
instant sank gradually, and even slowly, down to the ground; while
the old woman held her up as well as she could, calling to some one
within for assistance.
"Thank you. Oh, thank you," she said, as soon as she could
speak; "how kind you are."
Adelaide took her hand and pressed it in her own; and the
servant hastened away for the things she had been ordered to
procure. The nun's gown which Adelaide had worn throughout the
day had been already taken off, and she now lay in the ordinary
dress of a woman of high rank, which was more distinctly marked
from the garments of the lower orders in those days than at present.
Her station, therefore, could not be doubted; but yet in the look of
deep interest with which the lady gazed upon her, there seemed
something more than the mere compassion which might well be felt
for one accustomed to every comfort and refinement, exposed
suddenly to hardships, dangers, and fatigues, and sinking under
them. It was a long, thoughtful, wistful look that she fixed upon her.
It seemed to scan her face, and ask deep questions of her heart and
mind. It was rather, as if it said, what is beneath that lovely
countenance? what spirit is within that graceful form? than merely,
what are you? what is your name and place in the cold order of this
world's classes? But when the poor girl pressed her hand, and
looked up with eyes full of petition as well as thanks, the lady smiled
sweetly; and yet some drops gathered in her eyes, and one or two
rolled over and bedewed her cheek. Then, bending down her head--
perhaps in some degree to hide the tears--she kissed the marble
forehead that lay beneath her eyes, and whispered, "You will soon
be better.--Hush!--Be patient for a while; we will talk more anon."
The voice was very musical, soft, low, and sweet, with a slight
foreign accent; but still so expressive of kindness and tenderness,
that had it even used an unknown language, Adelaide would have
understood right well its tones of sympathy.
"I am well, now, indeed," she murmured; "and I must thank you
from my heart, dear lady, for your kindness."
"Fie!" said her companion; "if you would thank me really, lie still
till you have taken some nourishment. Then you shall speak, and tell
me all that has befallen you. Oh! here is Biancha--Now take a little
wine. Dip a morsel of bread in it first, and swallow that. Then sip the
rest. It will not do you harm."
But she did not finish the sentence; and after her fair guest had
taken the wine, she aided the maid to change the wet garments,
and put on some loose clothing for her, which, if it fitted not quite
well, at least felt warm and comforting.
"Now lie and rest," said the lady, "and tell me how this has been.
The girl who let you in says, that you were travelling under the
guard of some men from the abbey--What abbey did she mean?--
that near Ehrenstein?"
"At the edge of the wood, hard by," answered Adelaide, not
anxious to be questioned too closely upon other subjects, "they saw
a party of armed men, who seemed about to attack them; and they
told me, with the maid, to ride back and wait at a woodman's shed,
where we had found shelter some time before from the storm. I
rode away in terror, thinking that Bertha followed; but--how or why,
I know not--she never came. I fear the men of the abbey were
attacked and discomfited, for I heard horses galloping furiously past,
as if in flight and pursuit; and soon after they came up towards the
place where I was, and I fled amongst the trees, on foot, and
watched them from behind the bushes. They did not seek for me
far; but took away my horse, which I had left standing, weary, there.
Thus it was that I was forced to find my way onward alone, with
night coming on."
"And whither were you going, my child?" asked the lady, gazing at
her face somewhat earnestly.
Adelaide hesitated, but she could not well evade the question;
and she answered at length, in a low tone, "To Heiligenstein, lady."
The lady instantly cast her arms around her, and kissed her
tenderly. "You are at Heiligenstein, my child," she whispered; "and it
was to me that George of Altenburg sent you. Rest in peace, dear
Adelaide; rest in peace. You are with a mother."
Those few words rendered all the poor girl's conclusions once
more vague and undefined. It might be but a form of speech she
had used, Adelaide thought; and Adelaide mused.
"And are you like your father?" asked the lady at length; after
having gazed for a minute or two on the countenance of the fair
creature before her, while the long, dark lashes of the downcast eyes
rested on her cheek as she meditated.
"I never saw him," replied the lady, thoughtfully, and even
gravely; but after a moment she went on--"We will ask each other
no more questions, dear girl. Here you can stay in safety and peace.
That is enough for the present; all the rest will soon be explained;
and between two agitated and apprehensive hearts, like Yours and
mine, it is better only to speak of things that may tranquillize and
reassure us."
"And are you, too, agitated and apprehensive?" asked Adelaide.
"How, then, can I rest here in peace?"
"Agitated! ay, and full of fears, I am, indeed," answered the lady;
"but they are not such as affect you, my child. If it is for Ferdinand
you fear, doubt not that he is safe, for I have had assurance of it; if
for yourself, set your mind at rest, for though this house may seem
but an insecure asylum against the pursuit of those who would take
you hence, yet, first, they know not where you are; and next, by the
side of the very bed on which you lie, is a door that leads at once
within the convent walls. That place is holy, and those walls are
strong. If there be men daring enough to try to force them, there is
power at hand to resist. Now, my child, I will leave you to repose;
for it is that which you most need. Sleep--and Heaven's best benison
be upon you!"
Carefully and kindly the lady shaded the lamp, but left it still
burning, placed a little silver bell by Adelaide's side, and assuring her
that if she needed aught, she had but to ring, and it would be
instantly brought to her, she kissed her with motherly tenderness,
and left her.
Adelaide leaned her head upon her hand; but her thoughts were
all bewildered with the events just passed. There are moments when
the mind is too busy for sleep to still its wild activity, but when the
agitation of the heart renders thought vain and fruitless. She could
not think,--she could not sleep: she could only feel. She was then,
for the first time, absent from her father's dwelling. She was the
bride of a single day, with her bridegroom absent she knew not
where. She was a fugitive among strangers, who were kind and
gentle to her; but who they were she knew not. She had passed
through dangers and fatigues such as she had never endured
before; and who could say when they might be renewed? How could
she either sleep or think when such impressions were all fresh upon
her? and there she lay till hour after hour had passed by,--till the
convent bell sounded midnight, and all seemed still and at rest but
the heavy marker of the passing time. Just then, however, she heard
a dull sound like the trampling of horses, and terror began to take
possession of her again. The sound came nearer and more near, and
she stretched out her hand to ring the bell which had been left by
her side, when suddenly rose up a strain of rich harmony in the
midst of the darkness and stillness of the night. Adelaide heard but
little of the lay, but thus sang a number of wild but fine voices, as
the cavalcade passed by:--
SONG.
CHAPTER XXXVII.
All was hurry and confusion during the morning, however; and
the castle looked more like a fortress, the garrison of which expected
immediate attack, than the dwelling of a high noble in a time of
peace. Parties were hourly coming in or going forth, messengers
arrived or were despatched continually, and even the hall and the
festive board were not free from business and importunity. The brow
of the Count of Ehrenstein remained as black as night; nothing could
move his lip to a smile; and as he sat at the head of the table in the
lesser hall, with a greatly diminished party around, his very look
spread gloom over the feast, and saddened the gayest hearts
present.
Count Frederick strove to comfort and console him; but the Lord
of Ehrenstein heard his words in silence, or replied in monosyllables.
The priest ate the rich food and drank the fine wine, without
venturing more than a few words in praise of both; the knights sat
round, and partook of their good cheer, with only a whisper amongst
themselves now and then; and no one spoke but the jester, who, as
usual, held on his captious course, as if nothing had occurred to
interrupt the merriment; or, at least, as if he were in utter ignorance
that such had been the case.
Those were days of privilege, when every prescriptive right,
however ridiculous and sometimes iniquitous it might be, was
reverenced as a part of a great system; and even the privilege of the
jester was held so sacred, that any man who ventured to show
serious anger at what he might say, would have been considered
either as a fool or a tyrant. Thus our friend, on the present occasion,
ventured, without the least fear, to touch upon all those subjects
which were most painful to the master of the dwelling; sometimes
wondering if the Lady Adelaide fared as well in the fields as they did
in the castle, sometimes choosing to suppose that Ferdinand of
Altenburg must have gained a goodly appetite by his early walk.
"Wrong, uncle--ever wrong," cried the jester; "for then would old
men get into mischief, too. God love you! there is as little sense
under a grey beard as under a brown one, and more than either
under none at all. Look you now, the Lady Adelaide has more sense
than her father, though she has no beard, and he has a long one;
and then he has more sense than I have, and his beard is but grey,
while mine is white. Try again, uncle, try again."
"I have you now," answered the Count: "it is want of experience,
you would say."
"Wrong once more," answered the jester. "See you not that those
who have had most experience still do foolish things. Who would
have thought that an armed lord, with well nigh five hundred men in
his train, would have trusted sundry sacks of gold to be carried by
peaceful merchants, when he could have brought it himself? No, no,
uncle: 'tis the great fault of all men--want of faith."
"Not a whit, not a whit," cried the jester. "Want of faith in all
things is bad; but I dabble not with religion. Let the cobbler stick to
his awl: I am a moralist and philosopher, not a priest; and yet I say
it is want of faith that gets young men into mischief; for, did we
believe what those who have tried tell those who have not tried, we
should 'scape many a danger. But we never do believe in this world;
we always think that we shall be better off than our neighbours, and
therefore wish to try for ourselves. Is not that morality for you now?
And see how it is proved every day. Cage your bird for its own good,
and it will beat itself to death to get out; or, leave the door open for
a minute, and it flies away to be pecked to death by the first hawk it
meets. Is it not so, good Count of Ehrenstein?"
"So do men get bloody fingers," answered the jester; "but, after
all, who is there among us that has not some stain upon his hand?
No one except myself, I warrant. There is a lily palm, with not a drop
of Christian blood upon it; and as for the gore of a few stray
Saracens, that but cleanses a man's fingers; as a farmer's maiden
uses sand, which is dirt, to scrub her father's floor."
"Ay, and what is that one?" said Count Frederick, turning to the
messenger also.
"Why, the Black Huntsman is out again, my lord," said the man;
"and old Seckendorf sent me back to let my lord know that all the
country is ringing with his doings. He rode all the way down the
valley last night, and some say, went down to the Rhine, while
others will have it, that he turned towards Zweibrücken."
"Did they stop at the abbey?" asked the Count of Ehrenstein, with
a sneering smile.
"No, my lord; they left it far to the left," was the man's answer,
"keeping along amongst the hills, until we lost them in the wood,
some six miles off."
"Well, let it come," said the Count musing, and speaking rather to
what was passing in his own thoughts, than in reference to anything
that had been said by others; "let it come. It shall go hard, if the
tide of war flows through this valley, but that one of the waves shall
sweep away the walls of the abbey--ay, and all that are within;" he
muttered between his teeth.
"My lord, my lord!" cried a man, who was seated near the
window; "here comes news at length, or I am mistaken. Some one
galloping like mad up from the bridge."
"Bring him up quick, as soon as he arrives," cried the Count of
Ehrenstein, turning to the attendants behind him; and the meal
resumed its course for a few minutes; though few of those
principally interested in the events which had taken place during that
morning and the preceding night, showed any great appetite for the
dainties before them.
At length, quick steps were heard in the outer chamber, and the
two Counts turned their faces towards the door with the eager look
of expectation. Some of the servants of the castle were the first that
appeared; but immediately behind them was a stranger, dressed in
the garb of the middle orders, and offering nothing very remarkable,
either in his person or apparel. The Count of Ehrenstein, as was not
unusual with him, fixed his eyes for a moment on the new comer,
without speaking. It seemed, as if he loved to question men's faces,
and to read the character in the countenance before he ventured
anything in words himself. It is not an unfrequent habit with all men
of dark and subtle natures; but before he could speak on the
present occasion, the person who thus sought his presence, looked
inquiringly from his countenance to that of Count Frederick of
Leiningen, and then asked, "Which is the Count of Ehrenstein?"
"I am he," replied the Count; "what would you with me, Sir?"
"I bring you this letter, my lord," answered the man; "I was told
to deliver it with all speed."
"Faith! my good lord, I do not know," replied the man; "it was a
young gentleman, of a fair countenance, and a good bearing, some
twenty years of age or so; and he gave me ten crowns out of his
purse, to carry it to you with all speed."