Functional Python Programming: Use a functional approach to write succinct, expressive, and efficient Python code, 3rd Edition Lott - Quickly download the ebook to explore the full content
Functional Python Programming: Use a functional approach to write succinct, expressive, and efficient Python code, 3rd Edition Lott - Quickly download the ebook to explore the full content
com
https://textbookfull.com/product/functional-python-
programming-use-a-functional-approach-to-write-succinct-
expressive-and-efficient-python-code-3rd-edition-lott/
OR CLICK HERE
DOWLOAD EBOOK
https://textbookfull.com/product/biota-grow-2c-gather-2c-cook-loucas/
textbookfull.com
https://textbookfull.com/product/functional-programming-in-c-how-to-
write-better-c-code-1st-edition-enrico-buonanno/
textbookfull.com
Function Python programming discover the power of
functional programming generator functions lazy evaluation
the built in itertools library and monads Second Edition
Lott
https://textbookfull.com/product/function-python-programming-discover-
the-power-of-functional-programming-generator-functions-lazy-
evaluation-the-built-in-itertools-library-and-monads-second-edition-
lott/
textbookfull.com
https://textbookfull.com/product/python-projects-for-beginners-a-ten-
week-bootcamp-approach-to-python-programming-milliken/
textbookfull.com
https://textbookfull.com/product/teach-your-kids-to-code-a-parent-
friendly-guide-to-python-programming-1st-edition-bryson-payne/
textbookfull.com
https://textbookfull.com/product/effective-python-90-specific-ways-to-
write-better-python-2nd-edition-brett-slatkin/
textbookfull.com
Functional Python
Programming
Third Edition
Steven F. Lott
BIRMINGHAM—MUMBAI
“Python” and the Python logo are trademarks of the Python Software Foundation.
Functional Python Programming
Third Edition
Copyright © 2022 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without the prior written permission of the publisher,
except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information
presented. However, the information contained in this book is sold without warranty, either express
or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held
liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and
products mentioned in this book by the appropriate use of capitals. However, Packt Publishing
cannot guarantee the accuracy of this information.
Python is an incredibly versatile language that offers a lot of perks for just about every
group. For the object-oriented programming fans, it has classes and inheritance. When
we talk about functional programming, it has functions as a first-class type, higher-order
functions such as map and reduce, and a handy syntax for comprehensions and generators.
Perhaps best of all, it doesn’t force any of those on the user – it’s still totally OK to write a
script in Python without a single class or function and not feel guilty about it.
Thinking in terms of functional programming, having in mind the goals of minimizing state
and side effects, writing pure functions, reducing intermediary data, and what depends on
what else will also allow you to see your code under a new light. It’ll also allow you to
write more compact, performant, testable, and maintainable code, where instead of writing
a program to solve your problem, you “write the language up”, adding new functions to
it until expressing the solution you designed is simple and straightforward. This is an
extremely powerful mind shift – and an exercise worth doing. It’s a bit like learning a
new language, such as Lisp or Forth (or German, or Irish), but without having to leave the
comfort of your Python environment.
Not being a pure functional language has its costs, however. Python lacks many features
functional languages can use to provide better memory efficiency and speed. Python’s
strongest point remains its accessibility – you can fire up your Python interpreter and
start playing with the examples in this book right away. This interactive approach allows
exploratory programming, where you test ideas easily, and only later need to incorporate
them into a more complex program (or not – like I said, it’s totally OK to write a simple
script).
This book is intended for people already familiar with Python. You don’t need to know
much about functional programming – the book will guide you through many common
approaches, techniques, and patterns used in functional programming and how they can
be best expressed in Python. Think of this book as an introduction – it’ll give you the basic
tools to see, think, and express your ideas in functional terms using Python.
Ricardo Bánffy
Steven has been working with Python since the ‘90s, building a variety of tools and
applications. He’s written a number of titles for Packt Publishing, include Mastering
Object-Oriented Python, Modern Python Cookbook, and Functional Python Programming.
He’s a technomad, and lives on a boat that’s usually located on the east coast of the US. He
tries to live by the words, “Don’t come home until you have a story.”
About the reviewers
Alex Martelli is a Fellow of the Python Software Foundation, a winner of the Frank
Willison Memorial Award for contributions to the Python community, and a top-page
reputation hog on Stack Overflow. He spent 8 years with IBM Research, then 13 years
at Think3 Inc., followed by 4 years as a consultant, and lately 17 years at Google. He
has taught programming languages, development methods, and numerical computing at
Ferrara University and other venues.
Books he has authored or co-authored include two editions of Python Cookbook, four
editions of Python in a Nutshell, and a chapter in Beautiful Teams. Dozens of his interviews
and tech talks at conferences are available on YouTube. Alex’s proudest achievement are
the articles that appeared in Bridge World (January and February 2000), which were hailed
as giant steps towards solving issues that had haunted contract bridge theoreticians for
decades, and still get quoted in current bridge-theoretical literature.
Tiago Antao has a BEng in Informatics and a PhD in Life Sciences. He works in the
Big Data space, analyzing very large datasets and implementing complex data processing
algorithms. He leverages Python with all its libraries to carry out scientific computing and
data engineering tasks. He also uses low-level programming languages like C, C++, and
Rust to optimize critical parts of algorithms. Tiago develops on an infrastructure based on
AWS, but has used on-premises computing and scientific clusters for most of his career.
While he currently works in industry, he also has exposure to the academic side of scientific
computing, with two data analysis postdocs at the universities of Cambridge and Oxford,
and a research scientist position at the University of Montana, where he set up, from
scratch, the scientific computing infrastructure for the analysis of biological data.
Preface xxi
Index 53
Preface
Functional programming offers a variety of techniques for creating succinct and expressive
software. While Python is not a purely functional programming language, we can do a
great deal of functional programming in Python.
Python has a core set of functional programming features. This lets us borrow many design
patterns and techniques from other functional languages. These borrowed concepts can
lead us to create elegant programs. Python’s generator expressions, in particular, negate
the need to create large in-memory data structures, leading to programs that may execute
more quickly because they use fewer resources.
We can’t easily create purely functional programs in Python. Python lacks a number of
features that would be required for this. We don’t have unlimited recursion, for example,
we don’t have lazy evaluation of all expressions, and we don’t have an optimizing compiler.
There are several key features of functional programming languages that are available
in Python. One of the most important ones is the idea of functions being first-class ob-
jects. Python also offers a number of higher-order functions. The built-in map(), filter(),
and functools.reduce() functions are widely used in this role, and less obvious are
functions such as sorted(), min(), and max().
In some cases, a functional approach to a problem will also lead to extremely high-
performance algorithms. Python makes it too easy to create large intermediate data
structures, tying up memory (and processor time). With functional programming de-
sign patterns, we can often replace large lists with generator expressions that are equally
expressive but take up much less memory and run much more quickly.
xxii Preface
We’ll look at the core features of functional programming from a Python point of view.
Our objective is to borrow good ideas from functional programming languages and use
those ideas to create expressive and succinct applications in Python.
This is not intended as a tutorial on Python. This book assumes some familiarity with the
language and the standard library. For a foundational introduction to Python, consider
Learn Python Programming, Third Edition: https://www.packtpub.com/product/learn-p
ython-programming-third-edition/9781801815093.
While we cover the foundations of functional programming, this is not a complete review of
the various kinds of functional programming techniques. Having an exposure to functional
programming in another language can be helpful.
• Library modules to help create functional programs. This is the subject of the
remaining chapters of the book. Chapter 12 includes both fundamental language and
library topics.
Chapter 2, Introducing Essential Functional Concepts, delves into central features of the
functional programming paradigm. We’ll look at each in some detail to see how they’re
implemented in Python. We’ll also point out some features of functional languages that
don’t apply well to Python. In particular, many functional languages have complex type-
matching rules required to support compiling and optimizing.
Chapter 3, Functions, Iterators, and Generators, will show how to leverage immutable Python
objects, and how generator expressions adapt functional programming concepts to the
Python language. We’ll look at some of the built-in Python collections and how we can
leverage them without departing too far from functional programming concepts.
Chapter 4, Working with Collections, shows how you can use a number of built-in Python
functions to operate on collections of data. This chapter will focus on a number of relatively
simple functions, such as any() and all(), which reduce a collection of values to a single
result.
Chapter 6, Recursions and Reductions, teaches how to design an algorithm using recursion
and then optimize it into a high-performance for statement. We’ll also look at some other
reductions that are widely used, including collections.Counter().
Chapter 7, Complex Stateless Objects, showcases a number of ways that we can use immutable
tuples, typing.NamedTuple, and the frozen @dataclass instead of stateful objects. We’ll
also look at the pyrsistent module as a way to create immutable objects. Immutable
objects have a simpler interface than stateful objects: we never have to worry about
abusing an attribute and setting an object into some inconsistent or invalid state.
Chapter 8, The Itertools Module, examines a number of functions in the itertools standard
library module. This collection of functions simplifies writing programs that deal with
collections or generator functions.
xxiv Preface
Chapter 9, Itertools for Combinatorics – Permutations and Combinations, covers the combina-
toric functions in the itertools module. These functions are more specialized than those
in the previous chapter. This chapter includes some examples that illustrate ill-considered
use of these functions and the consequences of combinatoric explosion.
Chapter 10, The Functools Module, focuses on how to use some of the functions in the
functools module for functional programming. A few functions in this module are more
appropriate for building decorators, and they are left for Chapter 12, Decorator Design
Techniques.
Chapter 11, The Toolz Package, covers the toolz package, a number of closely related
modules that help us write functional programs in Python. The toolz modules parallel
the built-in itertools and functools modules, providing alternatives that are often more
sophisticated and make better use of curried functions.
Chapter 12, Decorator Design Techniques, covers how we can look at a decorator as a way
to build a composite function. While there is considerable flexibility here, there are also
some conceptual limitations: we’ll look at ways that overly complex decorators can become
confusing rather than helpful.
Chapter 13, The PyMonad Library, examines some of the features of the PyMonad library.
This provides some additional functional programming features. It also provides a way to
learn more about monads. In some functional languages, monads are an important way to
force a particular order for operations that might get optimized into an undesirable order.
Since Python already has strict ordering of expressions and statements, the monad feature
is more instructive than practical.
Chapter 14, The Multiprocessing, Threading, and Concurrent.Futures Modules, points out
an important consequence of good functional design: we can distribute the processing
workload. Using immutable objects means that we can’t corrupt an object because of poorly
synchronized write operations.
Chapter 15, A Functional Approach to Web Services, shows how we can think of web services
as a nested collection of functions that transform a request into a reply. We’ll see ways to
Preface xxv
leverage functional programming concepts for building responsive, dynamic web content.
Chapter 16, A Chi-Squared Case Study, is a bonus, online-only case study applying a number
of functional programming techniques to a specific exploratory data analysis problem. We
will apply a 𝜒 2 statistical test to some complex data to see if the results show ordinary
variability, or if they are an indication of something that requires deeper analysis. You can
find the case study here: https://github.com/PacktPublishing/Functional-Python-P
rogramming-3rd-Edition/blob/main/Bonus_Content/Chapter_16.pdf.
Some of the examples use exploratory data analysis (EDA) as a problem domain to show
the value of functional programming. Some familiarity with basic probability and statistics
will help with this. There are only a few examples that move into more serious data science.
Python 3.10 is required. The examples have also been tested with Python 3.11, and work
correctly. For data science purposes, it’s often helpful to start with the conda tool to create
and manage virtual environments. It’s not required, however, and readers should be able
to use any available Python.
Additional packages are generally installed with pip. The command looks like this:
In some cases, the reader will notice that the code provided on GitHub includes partial
solutions to some of the exercises. These serve as hints, allowing the reader to explore
alternative solutions.
In many cases, exercises will need unit test cases to confirm they actually solve the problem.
These are often identical to the unit test cases already provided in the GitHub repository.
The reader should replace the book’s example function name with their own solution to
confirm that it works.
In some cases, the exercises suggest writing a response document to compare and contrast
multiple solutions. It helps to find a mentor or expert who can help the reader by reviewing
these small documents for clarity and completeness. A good comparison between design
approaches will include performance measurements using the timeit module to show the
performance advantages of one design over another.
Conventions used
There are a number of text conventions used throughout this book.
CodeInText: Indicates code words in the text, database table names, folder names, filenames,
file extensions, pathnames, dummy URLs, user input, and Twitter handles. For example:
“Python has other statements, such as global or nonlocal, which modify the rules for
variables in a particular namespace.”
Preface xxvii
Bold: Indicates a new term, an important word, or words you see on the screen, such as in
menus or dialog boxes. For example: “The base case states that the sum of a zero-length
sequence is 0. The recursive case states that the sum of a sequence is the first value plus
the sum of the rest of the sequence.”
print("Hello, World!")
Get in touch
Feedback from our readers is always welcome.
General feedback: Email feedback@packtpub.com, and mention the book’s title in the
subject of your message. If you have questions about any aspect of this book, please email
us at questions@packtpub.com.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you have found a mistake in this book we would be grateful if you would
report this to us. Please visit https://subscription.packtpub.com/help, click on the
Submit Errata button, search for your book, and enter the details.
Piracy: If you come across any illegal copies of our works in any form on the Internet,
xxviii Preface
we would be grateful if you would provide us with the location address or website name.
Please contact us at copyright@packtpub.com with a link to the material.
If you are interested in becoming an author: If there is a topic that you have ex-
pertise in and you are interested in either writing or contributing to a book, please visit
http://authors.packtpub.com.
https://packt.link/r/1803232579
Your review is important to us and the tech community and will help us make sure we’re
delivering excellent quality content.
Random documents with unrelated
content Scribd suggests to you:
store of gratitude. In fact he had never even considered that he had
really rescued the child; he had simply carried her home.
He certainly felt grateful to Mrs. Dawson. It was not half as hard
to wait for trouble when he knew definitely that it was coming as it
was to sit around and wonder about it. He could act now. At first he
thought that he would go at once to Baxter’s, but he could not resist
the temptation to stay and try to find out who the men were who
were after him. He went quietly down to the corral, put the saddle
and bridle on Jed, and led him out a quarter of a mile in the
direction of Baxter’s quarters. He left the horse there in a well-
marked spot and stole cautiously back to his station near the cabin.
It was too dark to see his watch, but Scott judged that it must be
pretty close to midnight. Once more he settled down to wait and
listen but he knew what to expect now and was entirely free from
the creepy feeling of uncertainty which had so worked on his nerves
earlier in the night. After about an hour’s vigil he thought he heard a
faint sound far down the trail. He waited patiently but it was not
repeated. That, however, was not significant for they would probably
leave their horses at a safe distance and come the rest of the way
more quietly on foot. He continued to listen intently.
In about half an hour his patience was rewarded. A twig snapped
in the direction of the corral and a dark shadow crawled slowly
toward the cabin. Scott sat as still as the tree against which he
leaned. It made him shudder to think that he might have been in
that cabin with that crawling shadow sneaking up on him. The man
moved very cautiously and as silently as the death that he carried.
He avoided the glare of the light from the doorway and edged
around toward the side next to Scott. His progress was almost
imperceptible now but he finally reached the wall. He listened
intently for a moment and then raised himself cautiously to a level
with the window. For one second he stood in the glare of the
lamplight before he realized that there was no one within and then
he ducked quickly below the sill. He was quick to recognize the
disadvantage of being there in the light with a possible enemy in the
dark woods behind him.
Short as the time had been Scott had recognized Dugan and had
caught the gleam of light from something which glittered in his
hand. It was hard to realize that he had slept with that man for
three nights in that very cabin. He did not have long to think about it
for Dugan had made certain there was no one in the shack and was
retreating to the very patch of shade in which Scott was hiding. He
used the same stealthy caution with which he had approached the
cabin and seemed to Scott to be gliding toward him for all the world
like a snake. There was the same dull reflection every time he
advanced his right hand that Scott had noticed in the window. It
looked as though they were certain to meet if Dugan held to his
present course. Scott almost stopped breathing and braced himself
for the encounter. If only the man would come within reach. Scott
felt that he could handle Dugan if he could only get hold of him
before there was time to shoot.
Steadily the shadow advanced. Only eight feet separated him
from the man in the forest when he turned slowly toward the cabin
once more and settled down to watch. Scott could not have missed
him, as poor a shot as he was, but even now he was glad that he
was not armed. The idea of shooting a man in the back even when
that man was waiting to do the same thing to him was repulsive to
him.
Almost side by side the two men sat and watched in absolute
silence. Scott had been still for an hour before he came without
suffering the slightest inconvenience, now he suffered agonies. He
wanted to sneeze. He itched all over and had an almost
uncontrollable desire to scratch. His legs became cramped and he
felt that he would have to move them or scream. And still Dugan
waited patiently, toying silently with his revolver. Scott saw the
ridiculous side of the situation as well as the danger and grinned as
he planned what he would do when the day began to break.
Dugan seemed to realize that something was wrong. He rose
slowly and walked cautiously back to the window. He was bolder
now. His vigil had convinced him that there was no one around. He
made a careful survey of the inside of the cabin and then walked
boldly off in the direction of the corral.
Scott heaved a great sigh of relief, congratulated himself on his
foresight in getting Jed out of the way and sneaked cautiously out to
join him. Jed heard him coming and nickered loudly. Scott had no
doubt that Dugan heard it, but it was too late now to do him any
harm. He swung onto Jed’s back with a feeling of perfect safety and
cantered away to Baxter’s.
Baxter was standing in the door of his cabin waiting for him. “I
heard your horse a mile away,” he called in cheerful greeting. “Put
Jed in the corral and come tell me the story. I have been lying awake
all night just to hear it.”
CHAPTER XVI
AT THE RESERVOIR
Scott and Baxter lay awake far into the small hours of the
morning discussing the events of the past evening. Baxter had been
in the West long enough to have lost his aversion to a gun, if indeed
he had ever had any, and could not understand Scott’s scruples.
“If ever a man had need of gun,” he exclaimed, “you have now.
Here you are traipsing around the country with a bad man on your
trail and not so much as a cap pistol in your belt. Why, man, if you’d
had a gun there to-night you could have blown that skunk into
kingdom come and ended all this rumpus.”
“And thought about it all the rest of my life,” Scott replied.
Baxter looked at him hopelessly and gave it up. “Well, you ought
to be pretty safe up there at the dam if they don’t know you are
there. Ramsey is evidently looking out for you down there and I’ll
keep a weather eye on the pass here. Let’s go to sleep so that you
can get away from here in the morning before anybody sees you.”
The nerves of youth are easily settled and Scott was soon
sleeping as peacefully as though nothing had happened. At his first
snore Baxter raised up cautiously and crawled out of bed. He slipped
on his clothes and took his seat at the open doorway with his
revolver lying within easy reach. “Let that devil come snooping
around here,” he muttered, “and I’ll see how my scruples work on
him.”
At the first streak of day the faithful guardian arose and quietly
prepared breakfast. “Come out of it, Burton, and throw some of this
into you,” he called to Scott when all was ready.
“Why didn’t you call me earlier?” Scott complained.
“Because I had not been out dodging bullets all night and did not
need the sleep.”
“How about grub up there at the dam?” Scott asked. “I don’t
know anything about the place and never thought about provisions
last night.”
“Strange, not having anything else to think about,” Baxter
commented sarcastically. “Better take along a few things from here
to make sure, but the cabin up there is usually pretty well stocked, I
think. If you are ready we better be going; we are not so likely to
meet any one on the trail now.”
He threw such perishable provisions as he happened to have into
a bag and started for the corral. Scott saw him pick his revolver up
from the bench by the door and stick it into his holster.
It was just light enough to see when they started up the trail
which led over the pass. They were nearly to the place where they
were fighting the fire the day before when Baxter turned from the
trail into the heavier timber.
“What’s the big scare now,” Scott asked looking curiously around.
“May not be anything in it,” Baxter replied, “but old Benny up
there in the lookout tower has eyes like a hawk. If he sees anything
moving within fifty miles he hauls out those old field glasses and
identifies it. He might recognize you and spread the news all over
the country. He is all right and would not tell any one if he knew why
you were going, but he doesn’t know and has nothing to do but talk
gossip over the ’phone.”
So they stuck to the hillside in spite of the rough going and
managed to keep out of Benny’s sight.
“Now you are all right,” Baxter assured him. “This trail is not very
good but you can follow it easy enough and it will lead you straight
to the dam. There is not supposed to be any one up that way, but if
you should see any one duck.”
“I suppose there is a telephone up there?” Scott asked.
“Yes, and you better listen in on every call you hear, because
some of us may want to warn you, but don’t talk unless you are sure
who it is. They might try to locate you that way.”
“Well, so long,” Scott said, “I certainly appreciate what you have
done for me.”
“Haven’t had a chance yet,” Baxter replied cheerfully, “but I am
praying for the opportunity. Don’t you think you better take my gun?
I have another at the cabin.”
“No,” Scott laughed, “I might shoot myself. So long.”
Once more he was alone with his thoughts, taking to the hills like
a hunted animal and not knowing who might be on his trail or
where. At least he felt certain that no enemies were ahead of him
and he did not fear those who followed as long as he was in the
open. He was going into a new country and that always pleased him.
The thought of his dangers was soon wiped out by the wildness and
ruggedness of the mountains around him.
This trail was little more than a cow track and he lost sight of it
several times, but Jed followed it as easily as a hound no matter
how vague it seemed to Scott. If this was the only trail to the dam
he thought the supervisor had picked a very good hiding place for
him. Here and there the mountains receded enough to make a fairly
respectable valley, but for the most part they crowded in pretty close
and left little more than a narrow cañon. There were traces of a dry
stream bed in the bottom of it and Scott guessed that it was the
spillway for the dam in time of flood. He noticed that if there should
be much of a run-off there would be scant room for the trail.
After two hours of steady climbing Jed emerged into a small flat,
grassy and an ideal meadow. At the upper end of the flat was a
heavy mason work wall, twenty feet high in the middle and
stretching clear across from slope to slope. Back of it was a great
amphitheater surrounded by mountain peaks. It was a magnificent
picture and Scott sat for a few minutes drinking it in. The grandeur
of it awed him a little, but it had a wonderful, mysterious beauty that
fascinated him. He had often read of the eagle’s eyrie on the
mountain peaks and now he felt that he had found it. The prospect
of a week in that little cabin on the end of the dam would have been
an unadulterated joy to him if it had not been for the silent hunter
on the slopes below.
“Well, Jed, old boy, they were mighty considerate of you, anyway.
I don’t know what there is in that cabin but if it is half as well
stocked as this meadow I’ll be satisfied.”
He threw the saddle and bridle on the ground in one corner of the
meadow near the end of the dam and turned Jed loose to graze. A
tiny stream trickled through the dam, in one place, filling a little
basin in the sod of the meadow. Jed drank long and deep and
seemed perfectly contented with his surroundings. There was no
danger of his wandering off even if he had not been so faithfully
attached to Scott. No dog could have thought more of its master.
An examination of the cabin showed ample supplies to withstand
a long siege. The view back into the encircling mountains was
superb and down through the cut of the cañon was a vista of hill
and gorge that extended clear to the main valley miles away. There
was eighteen feet of crystal clear water in the reservoir which was
about twenty acres in extent. To a man from the lake-sprinkled
section of New England it was a welcome sight. It was the most
water he had seen in that semi-arid country.
The dam itself was a rather poorly constructed mason work affair
and its safety was a matter of anxiety every spring to the ranchers
who lived in the valley below. Since it had come into the hands of
the Service, a man had been stationed there whenever the melting
of the snows in the surrounding mountains threatened an overflow.
Scott could not imagine a more pleasant job under normal
conditions. He even felt that he could enjoy it now for he felt very
little fear of not being able to take care of himself in such a place.
He marked the height of the water so that he could note its
progress and went back into the cabin to fix it up for his occupancy.
It was a cozy little place but Scott had not been in there long when
he began to feel uneasy. The same old feeling of being trapped was
stealing over him once more. He kept going to the door to peer
down the cañon, and was constantly glancing at the window, half
expecting to see Dugan’s leering face and that glittering something
in his hand. He tried his best to forget it and busy himself with the
work in hand, but he could not do it. A few minutes in the open
restored his nerve perfectly, but it began slipping again as soon as
he returned to the cabin.
Scott hated to give in to these fears which he felt were almost
entirely unwarranted, but he was forced to recognize that it would
be out of the question for him to stay in the cabin. He would go
crazy in there. It was a new sensation for a man who had always
prided himself on not having any nerves, and just because it was
new it was harder to bear.
“It’s no use,” Scott admitted to himself after struggling for an hour
to stick it out. “I might as well own up to being a coward and act
accordingly.”
He went outside and looked for a good place to camp. There was
no tent in the outfit but he did not need one. It seldom rained and if
it should the cabin was there for shelter. He selected a little flat
bench on the side of the cañon, near the cabin and slightly above it.
It was backed by steep, overhanging rocks and could be approached
only from the direction of the cabin. He could overlook the trail up
the cañon but was protected from view by a thin screen of aspens.
He soon had a cozy little nest rigged up there and felt all his old
assurance returning. The house was the handicap; here in the open
he felt on an even footing with every man. The telephone was his
problem now. He was supposed to listen for messages from below
and yet he felt that he could not even listen intelligently cooped up
there in the cabin corner with that ’phone where he could not even
see out of the door or window.
A brilliant idea occurred to him. Why not move the ’phone up to
the camp? There were tools for repairing the telephone line in all the
cabins; he had everything that he needed. In an hour he had moved
the instrument to the trunk of a little tree beside his camp and had
reconnected it by extension wires. He ran his ground wire down into
the water of the reservoir. He remembered his experience in trying
to hold up a receiver for two or three hours and made a crude wire
sling to hold it. Thus equipped like a telephone central he could
listen indefinitely without inconvenience.
His new home satisfactorily furnished and equipped with all the
modern conveniences, he set out to make a more comprehensive
examination of the reservoir. There were a number of small streams
running into it. During the heat of the day when the sun shone
warm on the ice-capped peaks and melted the drifting snow in the
deep packed cañons these streams delivered a considerable volume
of water, but in the cool of the night they shrunk to a mere trickle,
some of them ceasing to flow altogether.
Scott followed one of the larger ones away back and up to its
hidden sources. He found side cañons packed with snow to the very
rims and out of the bottom of each there trickled a tiny stream of ice
cold water. In other places there were miniature glaciers thrusting
their icy beaks out into the main cañon and melting as they
advanced. The snow in the open was pretty well gone and there
seemed to be little danger of a flood from those frozen reservoirs
hidden so effectually from the direct rays of the sun.
There was only one great danger. Rain!
A heavy rainstorm on those barren peaks would inevitably mean
an overwhelming flood. Most of the watershed was bare rock and
there was very little vegetation to hold the rush of the assembled
waters from the smooth worn channels of the ancient streams. Nor
were there any pools or backwaters to delay the floods; nearly all
were straight, narrow chutes leading to the reservoir below.
“One good thunder storm like we have at home,” Scott thought,
“would spill the water over the top of that dam before a fellow had a
chance to open the flood gates; but they don’t have them here, it
just snows summer and winter.” And so it did as a rule. Only a storm
on an exceptionally warm day would produce rain at that altitude.
He climbed one of the lower peaks and there, perched on a block
of old volcanic rock, he had the whole country laid out before him.
The group of old Benny’s lookout, which had seemed so high on the
ridge above the valley cliffs, lay far below him. He could see the line
of the cliffs and the fringe of trees along the stream in the main
valley. A jutting rock was all that cut off the view of the town. The
reservoir looked like a toy lake on the stage. There was quite a
breeze up there on the rocks, but not a ripple marred the reflections
on the surface of the pond. He could even see Jed feeding
peacefully in the little meadow which appeared like a splotch of
bright green paint spilled in the middle of an otherwise sombre
picture. There was no limit to the view.
He searched all those miles of country within his vision for
another moving object; there was none to be seen. He heaved a
little sigh of relief and wondered when the time would come that he
would be freed from the anxiety of watching for that pursuing
shadow. It had been haunting him less than twenty-four hours, but
they seemed to him like an eternity.
However, the worry had not yet affected his appetite and he
started for the camp. He had climbed farther than he had realized. It
took almost an hour of steady climbing to get down to the reservoir.
He approached the camp cautiously but there was no trace of any
one having been there and a nicker of welcome from the meadow
told him that all was well with Jed. He ate his supper in comfort, put
on his improvised head gear, and settled back against a mossy rock
to listen to the gossip of the evening.
He watched the shadows chase the retreating sunlight up the
eastern peaks and saw those shadows slowly deepen into darkness
as the short twilight faded and disappeared. The world had gone to
sleep and there came to his ear on the hushed night air the tinkling
trickle of the little mountain streams and the plash of the water
dripping through the dam. Suddenly the tips of the western peaks
glowed white and the shadows came slowly down before the silver
rays of the rising moon.
And not a word from the telephone. Either the people were
unusually silent to-night or he had made some mistake in
reconnecting his instrument. He was half dozing now, gazing
dreamily at the moon herself balanced on the rim of the eastern
peaks when he heard a faint click. It might have been the click of a
receiver on the line or it might have been the cocking of a revolver.
Scott was wide awake now, as wide awake as he had ever been in
all his life. He had been asleep and had that dreaded shadow stolen
on him unawares, or was it only the telephone line? He had been too
nearly asleep to know. For the next few minutes he sat with every
sense alert and nerves on edge while he searched every shadow
with anxious eye and listened in vain for the slightest suspicious
sound. With a second slight click in the receiver he relaxed with a
gasp of relief that could have been heard at the other end of the line
if he had been anywhere near the transmitter.
It was another of those silent calls such as he had intercepted
once before. He would have sworn that there were two men on that
line now waiting to see if they had a clear field.
“Benson?” Scott recognized Dawson’s voice. Benson was the
grouchy clerk in the supervisor’s office. So he belonged to the ring!
Scott was glad of it; he had never liked the man but this was the
first evidence that he had discovered against him.
“Well?” came the answer after a pause.
“Where did they assign the boob?”
“To watch the dam. Tried to tell you last night.”
“Dugan and I were calling on him then.”
“Going up?”
“To-morrow.”
“Shoot one for me.”
Two soft clicks and all was still.
So Mr. Dawson was coming to call in the morning. Well, Scott was
glad to know it. Moreover, it made him feel that he was fairly safe
from any visitors before that time. With this assurance he rolled in
his blanket and went to sleep.
CHAPTER XVII
AN ATTEMPT AT BRIBERY
There was no time to waste in mourning over the fate of the two
outlaws. Scott’s first duty was to the unsuspecting ranchers in the
path of the coming flood. The waves were already washing over the
top of the dam and the old sluice gates were groaning under the
strain. The storm still raged in unabated fury. Everywhere there was
running water. It was coming down the face of the rocky slopes in
sheets and all the cañons were filled with boiling torrents. The roar
of it sounded like a mighty accompaniment to the booming of the
thunder.
Before the echoes of the pistol shots had been swallowed up in
the other noises of the storm Scott sprang for the windlass, but he
was too late. Jed Clark was dead but he had accomplished his crazy
purpose. With a crash and rending of heavy timbers the sluice gates
went out on the crest of the flood and carried a small portion of the
dam with them. The whole structure trembled from end to end.
Scott felt the mason work crumbling under his feet and the swirling
waters grasping at his ankles. He scrambled desperately out of its
clutches and rushed to the place where he had left Jed. He was
gone, but a frightened snort from higher up the steep side of the
cañon led him to where the terrified horse had climbed to the base
of the perpendicular wall of rock and stood trembling, too frightened
to move.
The one chance now was to beat out the flood. To reach the
ranchers in the valley below before the wall of water which would
come when the dam went out, and that could be only the matter of
minutes now. It was a desperate chance, for the trail was steep and
rough, and the rush of the waters would make it almost impassable
in places.
Scott flung himself onto Jed’s trembling back and turned him
down the cañon trail. Another crash in the direction of the dam sent
him plunging ahead, and once started a mad fright took possession
of him. He ran like a fiend. Scott had learned much about riding
since he had cleared the corral fence clinging to Jed’s neck, but it
required all his skill to stay in the saddle now. He had to close his
eyes to protect them from the twigs which slashed his face, and
once a jagged point of rock grazed his knee and almost threw him
from the horse’s back.
“It’s up to you, Jed, old boy,” Scott whispered in the horse’s ear, “I
can’t help you any now.”
The roar of the torrent was always with him. Now the trail dipped
down to its very edge, into it once; now it climbed high on the side
of the cañon and skirted a narrow ledge at the edge of a wall of
rock. The hollow booming of the waters hinted of sickening depths
within easy reach of a misplaced foot. It seemed marvelous to Scott
that Jed could run at that breakneck speed on such rugged ground,
but the horse had been born in the mountains, had raced over them
all his life, and he never stumbled.
He was gaining on the flood. Already he had passed the crest of
the wave from the shattered sluice gates. There was water in the
stream, plenty of it, from the drainage below the dam, but it was not
the raging torrent which it had been higher up. The storm was
lessening now. A star or two were peeping through the rifts in the
black clouds and the profiles of the mountains were beginning to
loom in darker shadows. Scott recognized the ridge ahead where the
lookout station was located. He had to turn to the left there and
follow the valley instead of going up over the pass the way he had
come. From there on the country was wholly new to him and he
would have to trust entirely to Jed. He wondered whether he ought
to try to stop at the station and get Benny to telephone the news.
A dull roar like the rumble of distant thunder shook the mountain
and Scott knew that the dam had given way. There was no time to
lose now. The rush of water from the sluice gates would be like a
dribble compared with the mighty avalanche of water which would
roar down the valley now. Moreover, Jed was not yet under control
and he would do well if he could hold him in the valley trail, to say
nothing of stopping at Benny’s.
He began to talk soothingly to Jed and tried to steady him a little.
As he approached the turn in the valley he made out a figure
standing on the opposite edge of the stream. He recognized Benny
and tried to stop, but Jed was not yet ready to listen to reason. Scott
succeeded in turning him, probably because he did not want to cross
the stream, but he could not stop him. He had no control over him
at all.
“The dam is gone. Telephone,” he shouted at the top of his voice
as he rushed past. Either Benny did not understand or could do
nothing for he stood there quietly on the edge of the stream and
listened to the roar of the cañon.
The ground was more even here in the wider valley, and much
easier going for the horse. He had already covered five miles at that
terrific pace, and although it did not seem to be telling on his
splendid physique it seemed impossible for any animal to keep that
up for the remaining fifteen miles to the valley. Scott began to talk
to him once more. It was the only influence to which the big horse
had ever seemed susceptible. There was no longer the roar of the
water in the cañon to frighten him. There were not the same
deafening thunder crashes with their weird reverberations, the
rending of the gates was fading from his memory. Gradually Scott
could feel the straining effort lessening. He was still making splendid
time, but he was running more smoothly and he turned back his ear
to listen when Scott talked to him.
Four miles of that smooth running in the upper valley and then
down the steep trail to the main valley in which the town was
located. The trail came out to the plain near the home of the last
rancher whom Scott had gone to see about the free use permits. It
was here that the strange procession had ended that day. As Jed
shot out of the cañon into the open a man’s form darkened the
lighted doorway. Evidently he had heard the clatter of the rapidly
approaching hoofs on the rocky trail.
Scott slowed down and shouted, “The dam has burst. You better
beat it. Telephone the others.”
He loosened the rein and Jed sped on. The figure disappeared
instantly and looking back over his shoulder Scott could see the
lights bobbing about the house. It was a warning of disaster to those
people and they did not hesitate. It meant the destruction of their
homes and all of their possessions which they could not move to the
higher ground along the base of the valley cliffs.
At each of the other houses he had to stop and shout to get the
people out. They had had no warning. The whole telephone system
had been disabled by the storm. The message delivered, there was
no delay, no stopping to get an explanation. The men sprang silently
back to the houses and wasted none of the precious moments which
were left them. They had been living in dread of just this thing for
years and now it had come. They had been fearing it too long to be
in any doubt as to what to do now.
All along behind Scott men were fleeing from their homes as from
a pestilence with their families and most valuable possessions in
wagons and driving their stock before them. There was many a
backward glance at the homes which would probably be ruined
when they saw them again.
After each stop Scott watched Jed anxiously to see if he was in
distress but each time the noble animal took up his task willingly and
was soon back in his swinging run which sent the miles flying behind
him.
There was nothing ahead of him now but the town only two miles
away, and Jed was pounding over the level plain with hoof beats as
regular as the ticking of a watch. The town was all aglow with lights
and the people were busy with their everyday affairs, ignorant of the
impending danger.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
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.
textbookfull.com