Programming ERLANG Software for a Concurrent World 1st Edition Joe Armstrong pdf download
Programming ERLANG Software for a Concurrent World 1st Edition Joe Armstrong pdf download
https://ebookname.com/product/programming-erlang-software-for-a-
concurrent-world-1st-edition-joe-armstrong/
https://ebookname.com/product/erlang-programming-1st-ed-edition-
francesco-cesarini/
https://ebookname.com/product/programming-elixir-functional-
concurrent-pragmatic-fun-1st-edition-dave-thomas/
https://ebookname.com/product/concurrent-and-real-time-
programming-in-ada-3rd-edition-alan-burns/
https://ebookname.com/product/research-methods-in-
sociolinguistics-a-practical-guide-1st-edition-janet-holmes/
Gustav Klimt Best of 2nd ed Edition Jane Rogoyska
https://ebookname.com/product/gustav-klimt-best-of-2nd-ed-
edition-jane-rogoyska/
https://ebookname.com/product/the-chemistry-of-radical-
polymerization-2nd-edition-graeme-moad/
https://ebookname.com/product/infrared-spectra-of-rubbers-
plastics-and-thermoplastic-elastomers-4th-edition-yvonne-davies/
https://ebookname.com/product/zora-neale-hurston-and-american-
literary-culture-1st-edition-m-genevieve-west/
https://ebookname.com/product/hitler-s-crusade-bolshevism-and-
the-myth-of-the-international-jewish-conspiracy-waddington/
Consumer behavior buying having and being Ninth
Edition. Edition Michael R. Solomon
https://ebookname.com/product/consumer-behavior-buying-having-
and-being-ninth-edition-edition-michael-r-solomon/
The world is parallel.
If we want to write programs that behave as other objects behave in
the real world, then these programs will have a concurrent structure.
Use a language that was designed for writing concurrent applications,
and development becomes a lot easier.
Erlang programs model how we think and interact.
Joe Armstrong
Programming Erlang
Software for a Concurrent World
Joe Armstrong
Every precaution was taken in the preparation of this book. However, the publisher
assumes no responsibility for errors or omissions, or for damages that may result from
the use of information (including program listings) contained herein.
Our Pragmatic courses, workshops, and other products can help you and your team
create better software and have more fun. For more information, as well as the latest
Pragmatic titles, please visit us at
http://www.pragmaticprogrammer.com
ISBN-10: 1-9343560-0-X
ISBN-13: 978-1-934356-00-5
Printed on acid-free paper with 50% recycled, 15% post-consumer content.
P1.1 printing, July, 2007
Version: 2007-7-17
Contents
1 Begin 12
1.1 Road Map . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.2 Begin Again . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.3 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . 17
2 Getting Started 18
2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.2 Installing Erlang . . . . . . . . . . . . . . . . . . . . . . 21
2.3 The Code in This Book . . . . . . . . . . . . . . . . . . . 23
2.4 Starting the Shell . . . . . . . . . . . . . . . . . . . . . . 24
2.5 Simple Integer Arithmetic . . . . . . . . . . . . . . . . . 25
2.6 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.7 Floating-Point Numbers . . . . . . . . . . . . . . . . . . 32
2.8 Atoms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.9 Tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.10 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2.11 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
2.12 Pattern Matching Again . . . . . . . . . . . . . . . . . . 41
3 Sequential Programming 43
3.1 Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.2 Back to Shopping . . . . . . . . . . . . . . . . . . . . . . 49
3.3 Functions with the Same Name and Different Arity . . 52
3.4 Funs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
3.5 Simple List Processing . . . . . . . . . . . . . . . . . . . 58
3.6 List Comprehensions . . . . . . . . . . . . . . . . . . . . 61
3.7 Arithmetic Expressions . . . . . . . . . . . . . . . . . . 64
3.8 Guards . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
3.9 Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
3.10 case and if Expressions . . . . . . . . . . . . . . . . . . 72
3.11 Building Lists in Natural Order . . . . . . . . . . . . . . 73
3.12 Accumulators . . . . . . . . . . . . . . . . . . . . . . . . 74
CONTENTS 6
4 Exceptions 76
4.1 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . 76
4.2 Raising an Exception . . . . . . . . . . . . . . . . . . . . 77
4.3 try...catch . . . . . . . . . . . . . . . . . . . . . . . . . . 78
4.4 catch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
4.5 Improving Error Messages . . . . . . . . . . . . . . . . . 82
4.6 Programming Style with try...catch . . . . . . . . . . . . 82
4.7 Catching Every Possible Exception . . . . . . . . . . . . 83
4.8 Old- and New-Style Exception Handling . . . . . . . . . 84
4.9 Stack Traces . . . . . . . . . . . . . . . . . . . . . . . . . 84
7 Concurrency 137
E Miscellaneous 419
E.1 Analysis and Profiling Tools . . . . . . . . . . . . . . . . 419
E.2 Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . 422
E.3 Tracing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
E.4 Dynamic Code Loading . . . . . . . . . . . . . . . . . . . 435
Index 507
Chapter 1
Begin
Oh no! Not another programming language! Do I have to learn yet another
one? Aren’t there enough already?
I can understand your reaction. There are loads of programming lan-
guages, so why should you learn another?
Here are five reasons why you should learn Erlang:
• You want to write programs that run faster when you run them on
a multicore computer.
• You want to write fault-tolerant applications that can be modified
without taking them out of service.
• You’ve heard about “functional programming” and you’re wonder-
ing whether the techniques really work.
• You want to use a language that has been battle tested in real
large-scale industrial products that has great libraries and an
active user community.
• You don’t want to wear your fingers out by typing lots of lines of
code.
Can we do these things? In Section 20.3, Running SMP Erlang, on
page 376, we’ll look at some programs that have linear speed-ups when
we run them on a thirty-two-core computer. In Chapter 18, Making a
System with OTP, we’ll look at how to make highly reliable systems that
have been in round-the-clock operation for years. In Section 16.1, The
Road to the Generic Server, on page 292, we’ll talk about techniques for
writing servers where the software can be upgraded without taking the
server out of service.
R OAD M AP 13
• Chapter 17, Mnesia: The Erlang Database, on page 313 talks about
the Erlang database management system (DBMS) Mnesia. Mnesia
is an integrated DBMS with extremely fast, soft, real-time
response times. It can be configured to replicate its data over sev-
eral physically separated nodes to provide fault-tolerant operation.
• Chapter 18, Making a System with OTP, on page 335 is the second
of the OTP chapters. It deals with the practical aspects of sewing
together an OTP application. Real applications have a lot of small
messy details. They must be started and stopped in a consistent
manner. If they crash or if subcomponents crash, they must be
restarted. We need error logs so that if they do crash, we can figure
out what happened after the event. This chapter has all the nitty-
gritty details of making a fully blown OTP application.
• Chapter 19, Multicore Prelude, on page 365 is a short introduction
to why Erlang is suited for programming multicore computers. We
talk in general terms about shared memory and message passing
concurrency and why we strongly believe that languages with no
mutable state and concurrency are ideally suited to programming
multicore computers.
• Chapter 20, Programming Multicore CPUs, on page 367 is about
programming multicore computers. We talk about the techniques
for ensuring that an Erlang program will run efficiently on multi-
core computers. We introduce a number of abstractions for speed-
ing up sequential programs on multicore computers. Finally we
perform some measurements and develop our third major pro-
gram, a full-text search engine. To write this, we first implement
a function called mapreduce—this is a higher-order function for
parallelizing a computation over a set of processing elements.
• Appendix A, on page 390, describes the type system used to doc-
ument Erlang functions.
• Appendix B, on page 396, describes how to set up Erlang on the
Windows operating system (and how to configure emacs on all
operating systems).
• Appendix C, on page 399, has a catalog of Erlang resources.
• Appendix D, on page 403, describes lib_chan, which is a library for
programming socket-based distribution.
B EGIN A GAIN 16
1.3 Acknowledgments
Many people have helped in the preparation of this book, and I’d like to
thank them all here.
First, Dave Thomas, my editor: Dave has been teaching me to write
and subjecting me to a barrage of never-ending questions. Why this?
Why that? When I started the book, Dave said my writing style was like
“standing on a rock preaching.” He said, “I want you to talk to people,
not preach.” The book is better for it. Thanks, Dave.
Next, I’ve had a little committee of language experts at my back. They
helped me decide what to leave out. They also helped me clarify some
of the bits that are difficult to explain. Thanks here (in no particular
order) to Björn Gustavsson, Robert Virding, Kostis Sagonas, Kenneth
Lundin, Richard Carlsson, and Ulf Wiger.
Thanks also to Claes Vikström who provided valuable advice on Mnesia,
to Rickard Green on SMP Erlang, and to Hans Nilsson for the stemming
algorithm used in the text-indexing program.
Sean Hinde and Ulf Wiger helped me understand how to use various
OTP internals, and Serge Aleynikov explained active sockets to me so
that I could understand.
Helen Taylor (my wife) has proofread several chapters and provided
hundreds of cups of tea at appropriate moments. What’s more, she put
up with my rather obsessive behavior for the last seven months. Thanks
also to Thomas and Claire; and thanks to Bach and Handel, Zorro and
Daisy, and Doris, who have helped me stay sane, have purred when
stroked, and have gotten me to the right addresses.
Finally, to all the readers of the beta book who filled in errata requests:
I have cursed you and praised you. When the first beta went out, I was
unprepared for the entire book to be read in two days and for you to
shred every page with your comments. But the process has resulted in
a much better book than I had imagined. When (as happened several
times) dozens of people said, “I don’t understand this page,” then I was
forced to think again and rewrite the material concerned. Thanks for
your help, everybody.
Joe Armstrong
May 2007
Chapter 2
Getting Started
2.1 Overview
As with every learning experience, you’ll pass through a number of
stages on your way to Erlang mastery. Let’s look at the stages we cover
in this book and the things you’ll experience along the way.
When you use COP, you break down problems and identify the natural
concurrency in their solutions. This is an essential first step in writing
any concurrent program.
On a Windows system, the command erl works only if you have installed
Erlang and changed the PATH environment variable to refer to the pro-
gram. Assuming you’ve installed the program in the standard way,
you’ll invoke Erlang through the Start > All Programs > Erlang OTP
menu. In Appendix B, on page 396, I’ll describe how I’ve rigged Erlang
to run with MinGW and MSYS.
Note: I’ll show the banner (the bit that says “Erlang (BEAM) ... (abort
with ∧G)”) only occasionally. This information is useful only if you want
to report a bug. I’m just showing it here so you won’t get worried if you
see it and wonder what it is. I’ll leave it out in most of the examples
unless it’s particularly relevant.
If you see the shell banner, then Erlang is installed on your system.
Exit from it (press Ctrl+G, followed by the letter Q, and then hit Enter
or Return).3 Now you can skip ahead to Section 2.3, The Code in This
Book, on page 23.
If instead you get an error saying erl is an unknown command, you’ll
need to install Erlang on your box. And that means you’ll need to make
a decision—do you want to use a prebuilt binary distribution, use a
packaged distribution (on OS X), build Erlang from the sources, or use
the Comprehensive Erlang Archive Network (CEAN)?
Binary Distributions
Binary distributions of Erlang are available for Windows and for Linux-
based operating systems. The instructions for installing a binary sys-
tem are highly system dependent. So, we’ll go through these system by
system.
Windows
You’ll find a list of the releases at http://www.erlang.org/download.html.
Choose the entry for the latest version, and click the link for the Win-
dows binary—this points to a Windows executable. Click the link, and
follow the instructions. This is a standard Windows install, so you
shouldn’t have any problems.
Linux
Binary packages exist for Debian-based systems. On a Debian-based
system, issue the following command:
> apt-get install erlang
Installing on Mac OS X
As a Mac user, you can install a prebuilt version of Erlang using the
MacPorts system, or you can build Erlang from source. Using MacPorts
is marginally easier, and it will handle updates over time. However,
MacPorts can also be somewhat behind the times when it comes to
Erlang releases. During the initial writing up this book, for example,
the MacPorts version of Erlang was two releases behind the then cur-
rent version. For this reason, I recommend you just bite the bullet and
install Erlang from source, as described in the next section. To do this,
you’ll need to make sure you have the developer tools installed (they’re
on the DVD of software that came with your machine).
4. From http://www.erlang.org/download.html .
T HE C ODE IN T HIS B OOK 23
Note: You can use the command ./configure - -help to review the available
configuration options before building the system.
Use CEAN
The Comprehensive Erlang Archive Network (CEAN) is an attempt to
gather all the major Erlang applications in one place with a common
installer. The advantage of using CEAN is that it manages not only
the basic Erlang system but a large number of packages written in
Erlang. This means that as well as being able to keep your basic Erlang
installation up-to-date, you’ll be able to maintain your packages as well.
CEAN has precompiled binaries for a large number of operating systems
and processor architectures. To install a system using CEAN, go to
http://cean.process-one.net/download/, and follow the instructions. (Note
that some readers have reported that CEAN might not install the Erlang
compiler. If this happens to you, then start the Erlang shell and give the
command cean:install(compiler). This will install the compiler.)
-module(shop1).
-export([total/1]).
This bar contains the path to the code within the download. If you’re
reading the PDF version of this book and your PDF viewer supports
hyperlinks, you can click the bar, and the code should appear in a
browser window.
5. From http://pragmaticprogrammer.com/titles/jaerlang/code.html.
S TAR TING THE S HELL 24
O NE does not like to say such things, but the English Sparrows
were very disagreeable people. And they are very disagreeable
people. Also, they always have been, and probably always will be,
very disagreeable people. They were the first birds to make trouble
among neighbors anywhere around the big house. If it had not been
that the Gentleman who lived there was so very tender-hearted,
their nests would probably have been poked down with poles long
before the eggs could have been laid in them. When Boys came
around with little rifles and ugly looking bags slung over their
shoulders, they were always ordered away and told that the
Gentleman would have no shooting near his house.
It is not strange then that the woodbine was full of Sparrows’ nests,
and that many of the evergreens also bore them in their top
branches. One had even been tucked in behind a conductor pipe,
and their owners hunted and argued and fussed all over the place.
There was just one way in which the English Sparrows were not
cared for like other birds around the big house. Silvertip was allowed
to eat all that he could catch. And you may be very sure that no
Robin ever called “Cat!” when he was ready to spring upon a
Sparrow.
“It may be wrong,” said one Robin mother, “but I cannot do it. I
remember too well how they have robbed my nests and quarrelled
with my friends. I say that they must care for their own children.
And if they do not—well, so much the better for Silvertip!”
You see that the birds were not angry at Silvertip for trying to eat
them. It was all to be expected, as they knew very well. It was not
pleasant, but it had to be, just as Worms and Flies had to expect to
be eaten, unless they were clever enough to keep out of the way of
birds. Only the quickest and strongest could live, so of course all the
young ones tried hard to become quick and strong.
When Miss Sparrow, from the nest behind the conductor pipe, was
old enough to marry, she had many lovers, and that was quite
natural. She was a plump and trim-looking bird, and pretty, too, if
one came close enough to her. Her feathers were gray and brown,
with a little white and black in places. Her bill was black, and her
feet were brown. She was very careful to keep clean, and although
she had to hunt food in the mud of the street, she bathed often in
fine dust and kept her wings and tail well up. Her lovers were
dressed in the same colors, but with more decided markings.
Her parents were very clever to think of building where they did;
and because they had such a large nest and so near the eaves of
the house, they were much looked up to by the other Sparrows.
They were very proud of their home, and especially on days when
the water running down the pipe made a sweet guggle-guggle-
guggling sound. Sparrows like noise, you know, and this always
amused the children and kept them quiet on rainy days.
All the young Sparrows who were not already in love, and a few who
were, began to court Miss Sparrow as soon as it was known that she
cared to marry. This was partly on her own account, and partly
because of her distinguished family.
Some birds would have waited for their suitors to speak first about
marriage. Miss Sparrow did not. The Sparrows are not very well
bred. “Of course I am going to marry,” she said. “I am only waiting
to make up my mind whom I will choose.”
They flocked around her as she fed in the dust of the road, all
talking at once in their harsh voices. When a team passed by, and
that was not often, they flew or hopped aside at the last minute.
When they settled down again there was always a squabble to see
who should be next to Miss Sparrow. Her lovers fought with each
other over choice seeds, but they let Miss Sparrow have everything
she wished. She always seemed very cross when her lovers were
around (as well as most of the time when they were not), and often
scolded and pecked at them. Sometimes one who was not brave,
and would not stand pain, flew away and began courting somebody
else.
After a while she had driven away so many that only two were left.
She flew at these, striking first one and then the other, until, brave
as they were, one went away. Then she turned to the suitor who
was left with a sweet smile. “I will marry you,” she said.
His wings were lame from her fighting him, his head smarted where
she had picked at it, and two or three small feathers were missing
from his breast. Miss Sparrow was certainly a strong bird, and he
knew that anybody who wanted her would have to stand just what
he had stood. He would have preferred to court as the Goldfinches
and Wrens do, by singing to their sweethearts, but that could not
be. In the first place, he could not sing, and in the second place she
would not have taken him until she had beaten him anyway. It
would have been more fun for him to fight some of the other birds
and let the winner have her, yet that could not be done either. If he
wanted to marry, he had to marry an English Sparrow, and if he
wanted to marry an English Sparrow he had to go about it in her
way. It would have been just the same if he had courted her sister
or her cousin.
The truth is that, although the Sparrow husbands swagger and brag
a great deal and act as though they owned everything in sight, there
is not one whose wife does not order him around. Miss Sparrow
would not have taken him if she had not made sure that she could
whip him.
“What do I need of a husband,” she said, “unless he will mind me?
And when I feel crosser than usual I want somebody always near
and at home, where I can treat him as I choose. That is what I care
for in a home.”
“Now,” she said, “if you are to be my husband, I will show you
where we are to build.”
Mr. Sparrow flew meekly along after her. You would be meek with
lame wings, a sore head, and three feathers off from your breast.
She led the way to the front west porch, where the syringa shoots
made a little hedge around it and a tall fir tree made good perching
places beside it.
“Where are we going to build?” asked Mr. Sparrow. He saw plenty of
good window ledges and places which would do for Robins and
Phœbes and other birds who plaster their nests. Yet he did not see a
single corner or big crack where a Sparrow’s nest could be made to
hold together.
“I will show you,” answered Mrs. Sparrow. She perched on the top of
a porch column and looked up at a small round hole nearly over her
head. It was the place where a conductor pipe had once run through
the cornice. Now the pipe had been taken away and the opening
was left. She gave an upward spring and flutter and went straight up
through the hole. “Come up!” she cried in the most good-natured
way. “Come up! This is the best place I ever saw. Our nest will be all
hidden, and no large bird or Squirrel can possibly get in. The rain
can never fall on it, and on cold days we shall be warm and snug.”
She did not ask him what he thought of it, and he did not expect her
to. So he just said, “It is a most unusual place.”
“That is what I think,” she replied. “Very unusual, and I would not
build in the woodbine like some Sparrows. No, indeed! One who has
been brought up in style beside a water-pipe, as I was, could never
come down to woodbine. It should not be expected.”
“I’m sure it was not, my dear,” said her husband.
“Very well,” said she. “Since you like this place so much, we may as
well call it settled and keep still about it until we are ready to build.”
Mr. Sparrow had not said that he liked it, yet he knew better than to
tell her so. If he did, she might leave him even now for one of her
other lovers. He really dreaded getting out through that hole, and let
her go while he watched her. She went head first, clinging to the
rough edges of the hole with both feet, let go with one, hung and
twisted around until she was headed right, then dropped and flew
away. Mr. Sparrow did the same, but he did not like it.
After a while they began nest-building, and all the straws, sticks, and
feathers had to be dragged up through the little round doorway to
the nest. Mrs. Sparrow did most of the arranging, while her husband
flew in and out more than a hundred times a day. She was a worker.
Any bird will tell you that. Still, you know, there are different ways of
working. Some of the people who do the most work make the least
fuss. Mrs. Sparrow was not one of these. When she did a thing, she
wanted everybody to know it, and since her building-place was
hidden she talked all the more to Mr. Sparrow.
“I am going to have a large nest,” she said. “So bring plenty of stuff.
Bring good things, too,” she added. “You have brought two straws
already that were really dirty, and this last stick isn’t fit to use. I will
push it back into a corner.”
Mr. Sparrow would have liked to tell her what hard work his was,
and ask her to use things he brought, even if they were not quite
what she wanted. He was too wise for this, however, so he flew out
and pitched into another Sparrow who was getting straws for his
wife. He tried to steal his straw, and they fought back and forth until
their wives came to see what was the matter and began fighting
also. When they stopped at last, the straw had been carried away by
a Robin, so neither had it. But they had had a lovely, loud, rough
fight, and Sparrows like that even better than straw, so they all felt
good-natured again.
Twice Mrs. Sparrow decided to move her nest a little this way or a
little that, and such a litter as she made when doing it! Some of the
best sticks fell down through the doorway, and the Lady swept them
off the porch. Then Mrs. Sparrow scolded her. She was not afraid of
a Lady. “She might have left them there,” she said. “I would have
had my husband pick them up soon. Yesterday she had the Maid put
some of her own horrid chairs and tables out here while they were
cleaning, and I never touched them.”
Mr. Sparrow flew up with a fine Turkey feather. “It came from the
Lady’s duster,” he said. “I think it will give quite an air to your nest.”
“Excellent!” cried his wife. “Just wait until I get ready for it.” He
clung patiently by one foot to the doorway. When that was tired he
changed to the other. When that was tired he perched on the top of
the column. He was very hungry, and he saw some grain dropped
from a passing wagon.
“Hurry up, my dear!” he called. “It is past my dinner-time already.”
“Wait until supper then,” cried his wife. “As if I hadn’t enough to do
without thinking about your dinner! Don’t let go of it or it will be
blown away.”
Then Mr. Sparrow lost his temper. He stuck that feather into a crack
near by, and flew softly away to eat some grain. He thought he
might be back in time to carry in the feather and his wife never
know where he had been. Unfortunately, he got to talking and did
not hear his wife call him.
“Mr. Sparrow!” said she. “Mr. Sparrow! I am ready for that feather.”
When he did not answer, she put her head out of the doorway.
There was the Turkey feather stuck into a crack, and in the road
beyond was her husband eating happily with several of his friends.
She looked very angry and opened her bill to speak. Then she
changed her mind and flew quietly off the other way. She went
straight to the Horse-block, where another old suitor was, the one
who had come so near winning her. “Mr. Sparrow has disobeyed
me,” she said, “and is actually eating his dinner when he should be
waiting by the nest to help me. I believe that I ought to have
married you, but better late than never. Come now.”
This was how it happened that when Mr. Sparrow’s stomach was
quite full, and he suddenly remembered his work, he flew back and
found the Turkey feather gone. In the eaves overhead he heard Mrs.
Sparrow telling somebody else what to do. He tried to force his way
up there. Every time he was shoved back, and not very gently either.
“You might better look for another home,” said Mrs. Sparrow’s voice.
“I have found another husband, one who will help me as I wish.
Good-by.”
That was the ending of Mr. Sparrow’s first marriage. It was a very
sad affair, and the birds talked of nothing else for a long time
afterward. Some said that it served him exactly right, because he
married to get into a fine family, when there were dozens of Sparrow
daughters much prettier and nicer than the one he chose. There
may have been something in this, for certainly if Mrs. Sparrow had
not been so sure of finding another to take his place, she would not
have turned him out in the way she did. It is said, however, that her
second husband had a hard life of it.
A RAINY DAY ON THE LAWN
W HEN the sun rose, that morning late in April, he tried and
tried to look at the big house and see what was happening. All
he could see was a thick gray cloud veil stretched between him and
the earth, and, shine as hard as he might, not a single sunbeam
went through that veil.
When the Blackbirds awakened, they found a drizzling rain falling,
and hurried on their waterproofs to get ready for a wet time.
Blackbirds are always handsome, yet they never look better than
when it rains. They coat their feathers with oil from the pockets
under their tails, as indeed all birds do, and then they fly to the high
branches of some tall and swaying tree and talk and talk and talk
and talk. They do not get into little groups and face each other, but
scatter themselves around and face the wind. This is most sensible,
for if one of them were to turn his back to the wind, it would rumple
up his feathers and give the raindrops a chance to get down to his
skin. When they speak, or at least when they have anything really
important to say, they ruffle their own feathers and stand on tip-toe,
but they ruffle them carefully and face the wind all the time.
When the Robins opened their round eyes, they chirped cheerfully to
each other and put on their waterproofs. “Good weather for us,”
they said. “It will make fine mud for plastering our new nests, and it
will bring out the Worms.”
The English Sparrows, Goldfinches, and other seed-eaters were not
made happy by the rain. With them it was only something to be
borne patiently and without complaining. The Hummingbirds found
fewer fresh blossoms open on cloudy days, and so had to fly farther
and work harder for their food. The Pewees and other fly-catchers
oiled their feathers and kept steadily at work.
“O MOTHER, IT IS RAINING!”
When the morning was nearly past, and the birds felt so safe that
they had grown almost careless, Silvertip wakened and felt hungry.
He walked slowly out of the kitchen door and looked at the grass.
The sun was now shining, and it was no longer sparkling with tiny
drops. He crept down the steps and around to a place under a big
spruce tree, the lower branches of which lay along the ground. A fat
Robin was hunting near by.
Silvertip watched her hungrily, and if you were a Cat you might have
done exactly the same thing. So you must not blame Silvertip. He
was creeping, creeping, creeping nearer, and never looking away
from her, when the Little Boy came tramping across the grass. He
had come in by the gate of the driveway, and was walking straight
toward Silvertip, who neither saw nor heard him.
Then the Little Boy saw what was happening, and dropped his bright
paper chain on the grass beside him. “G’way!” he cried, waving his
umbrella. “G’way! Don’t you try to eat any birds ’round here. My
father doesn’t ’low it. G’way! G’way! Else I’ll tell my mother that you
are a bad Cat.”
Silvertip fled under the porch, the Robin flew up onto the snowball
bush, and all around the birds sang the praises of the good Little
Boy with the umbrella. But the Little Boy didn’t know this. He stood
by the porch and dangled his pretty paper chain until Silvertip
forgave him and came out to play. Then they ran together into the
house, and the birds heard him shouting, “Mother! Mother! Where
are you? I want to give Silvertip some cream. He is so very hungry
that he most had to eat up a Robin, only I wouldn’t let him.”
THE PERSISTENT PHŒBE
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.
ebookname.com