Instant download Hands On Functional Programming in Rust 1st Edition Andrew Johnson pdf all chapter
Instant download Hands On Functional Programming in Rust 1st Edition Andrew Johnson pdf all chapter
com
https://textbookfull.com/product/hands-on-functional-
programming-in-rust-1st-edition-andrew-johnson/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/programming-rust-1st-edition-jim-
blandy/
textboxfull.com
https://textbookfull.com/product/asynchronous-programming-in-rust-1st-
edition-carl-fredrik-samson/
textboxfull.com
https://textbookfull.com/product/the-rust-programming-language-covers-
rust-2018-steve-klabnik/
textboxfull.com
https://textbookfull.com/product/the-rust-programming-language-1st-
edition-steve-klabnik/
textboxfull.com
Programming WebAssembly with Rust 1st Edition Kevin
Hoffman
https://textbookfull.com/product/programming-webassembly-with-
rust-1st-edition-kevin-hoffman/
textboxfull.com
https://textbookfull.com/product/network-programming-with-rust-1st-
edition-abhishek-chanda/
textboxfull.com
https://textbookfull.com/product/hands-on-mqtt-programming-with-
python-gaston-c-hillar/
textboxfull.com
https://textbookfull.com/product/asynchronous-programming-in-
rust-1-converted-edition-carl-fredrik-samson/
textboxfull.com
https://textbookfull.com/product/making-sense-of-the-ecg-a-hands-on-
guide-andrew-houghton/
textboxfull.com
Hands-On Functional
Programming in Rust
Andrew Johnson
BIRMINGHAM - MUMBAI
Hands-On Functional Programming in Rust
Copyright © 2018 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.
ISBN 978-1-78883-935-8
www.packtpub.com
mapt.io
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as
well as industry leading tools to help you plan your personal development and advance
your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos
from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF and
ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a
print book customer, you are entitled to a discount on the eBook copy. Get in touch with us
at service@packtpub.com for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a
range of free newsletters, and receive exclusive discounts and offers on Packt books and
eBooks.
Contributors
Integration testing 57
Summary 59
Questions 60
Chapter 3: Functional Data Structures 61
Technical requirements 61
Adjusting to changing the scope of the project 62
Gathering new project requirements 62
Architecting a change map from requirements 62
Translating expectations into requirements 63
Translating requirements into a change map 64
Mapping requirements directly to code 64
Writing the physics simulator 65
Writing the motor controller 69
Writing the executable to run a simulation 74
Writing the executable to analyze a simulation 78
Running simulations and analyzing data 81
Summary 85
Questions 85
Chapter 4: Generics and Polymorphism 86
Technical requirements 86
Staying productive during downtime 87
Learning about generics 87
Investigating generics 88
Investigating parametric polymorphism 90
Investigating generalized algebraic datatypes 93
Investigating parametric lifetimes 97
Defining lifetimes on ground types 97
Defining lifetimes on generic types 97
Defining lifetimes on traits 98
Defining lifetime subtyping 98
Investigating parametric types 99
Applying parameterization concepts 101
Parameterizing data 101
Parameterizing functions and trait objects 104
Parametric traits and implementations 106
Summary 110
Questions 110
Chapter 5: Code Organization and Application Architecture 111
Technical requirements 112
Shipping a product without sacrificing quality 112
Reorganizing the project 113
Planning content of files by type 114
Organizing the motor_controllers.rs module 115
[ ii ]
Table of Contents
[ iii ]
Table of Contents
[ iv ]
Table of Contents
[v]
Preface
Thanks for your interest in functional programming in Rust. Rust is a very young
programming language and is particularly new to the functional programming community.
Despite its age, the language provides a wealth of tools that are both practical and
sophisticated.
In this book, we will introduce general functional programming principles and how they
apply to Rust specifically. Our goal is to provide knowledge and a perspective on Rust that
will outlast small changes to language features. The pace of development of Rust is so fast
that during the course of writing the book we introduced new features as they became
available and relevant. We want to equip the reader to produce code for this fast-moving
environment such that they are prepared to best utilize new features as they are released.
Chapter 2, Functional Control Flow, introduces Rust control flow structures while explaining
how they are relevant to the functional style of programming. The expression-centric
nature of functional programming and Rust is illustrated through examples. Limiting as it
may be, the chapter also begins an ongoing project using only the procedural expression
style of programming.
Preface
Chapter 3, Functional Data Structures, introduces the reader to the various, highly
expressive data types available in Rust. Notably, the enum type is introduced, which holds
particular significance in functional programming. The project continues to grow to
incorporate a variety of these data types.
Chapter 5, Code Organization and Application Architecture, talks about some architectural
concerns, recommendations, and best practices. Designing and managing the
implementation of a software project is not formulaic. No project is the same, and few are
highly similar, thus no engineering procedure can capture the nuances of software
development. In this chapter, we provide the best tools available, and specifically, the best
that functional programming has to offer.
Chapter 6, Mutability, Ownership, and Pure Functions, digs into some of the more unique
features in Rust. This chapter introduces the concepts of ownership and lifetimes, which are
common stumbling blocks when learning Rust. The functional concepts of immutability
and pure functions are also introduced to help untangle some of the spaghetti that a naive
Rust programmer might generate when attempting to circumvent the rules of ownership in
Rust.
Chapter 7, Design Patterns, lists as many functional programming cheat codes that can fit
into a single chapter. The concept of functors and monads are explained with examples and
some casual definitions. The chapter also briefly introduces the style of functional reactive
programming and uses it to build a quick and dirty web framework.
Chapter 8, Implementing Concurrency, explains how to do multiple things at the same time.
Most of the chapter is spent clarifying the differences and relative strengths and
weaknesses between subprocesses, forked processes, and threads. The Rust thread
concurrency model is then assumed and more information is provided to clarify Rust-
specific logic regarding threads. Toward the end of the chapter, the actor model of
concurrency is introduced, which is a robust model of concurrency that can adapt to most
situations and programming paradigms.
[2]
Preface
Chapter 9, Performance, Debugging, and Metaprogramming, wraps up the book with some
miscellaneous tips for programming in Rust. The performance tips are not particularly
functional, but rather concerned primarily with language-specific details, general advice, or
relevant bits of computer science. Debugging introduces many tips on how to prevent bugs.
Also, how to use an interactive debugger is explained through examples.
Metaprogramming explains precisely how Rust macros and procedural macros work. This
is a great feature of Rust, but is not documented well, so it might be scary to approach.
[3]
Preface
Once the file is downloaded, please make sure that you unzip or extract the folder using the
latest version of:
The code bundle for the book is also hosted on GitHub at https://github.com/
PacktPublishing/Hands-On-Functional-Programming-in-Rust. In case there's an update
to the code, it will be updated on the existing GitHub repository.
We also have other code bundles from our rich catalog of books and videos available
at https://github.com/PacktPublishing/. Check them out!
Conventions used
There are a number of text conventions used throughout this book.
CodeInText: Indicates code words in text, database table names, folder names, filenames,
file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an
example: "Let's start by defining some of the type declarations for the physics module."
Bold: Indicates a new term, an important word, or words that you see onscreen.
[4]
Preface
Get in touch
Feedback from our readers is always welcome.
General feedback: Email feedback@packtpub.com and mention the book 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 www.packtpub.com/submit-errata, selecting your book,
clicking on the Errata Submission Form link, and entering the details.
Piracy: If you come across any illegal copies of our works in any form on the Internet, 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 expertise in
and you are interested in either writing or contributing to a book, please visit
authors.packtpub.com.
Reviews
Please leave a review. Once you have read and used this book, why not leave a review on
the site that you purchased it from? Potential readers can then see and use your unbiased
opinion to make purchase decisions, we at Packt can understand what you think about our
products, and our authors can see your feedback on their book. Thank you!
[5]
1
Functional Programming – a
Comparison
Functional programming (FP) is the second most popular programming paradigm, behind
only object-oriented programming (OOP). For many years, these two paradigms have
been separated into different languages, so as not to be mixed. Multi-paradigm languages
have attempted to support both approaches. Rust is one such language.
Being able to use functional style to reduce code weight and complexity
Being able to write robust safe code by utilizing safe abstractions
Being able to engineer complex projects using functional principles
Technical requirements
A recent version of Rust is necessary to run the examples provided, and can be found here:
https://www.rust-lang.org/en-US/install.html
Specific installation and build instructions are also included in each chapter's README.md
file.
Struct definitions can become redundant without generics. Here is a definition of three
structs that define a common concept of a Point. However, the structs use different
numerical types, so the singular concept is expanded into three separate PointN type
definitions in intro_generics.rs:
struct PointU32
{
x: u32,
y: u32
}
struct PointF32
{
x: f32,
y: f32
}
struct PointI32
{
x: i32,
y: i32
}
[7]
Functional Programming – a Comparison Chapter 1
Instead, we can use generics to remove duplicate code and make the code more robust.
Generic code is more easily adaptable to new requirements because many behaviors (and
thus requirements) can be parameterized. If a change is needed, it is better to only change
one line rather than a hundred.
This code snippet defines a parameterized Point struct. Now, a single definition can
capture all possible numerical types for a Point in intro_generics.rs:
struct Point<T>
{
x: T,
y: T
}
Function parameters, such as this one, may need trait bounds (a constraint specifying one
or more traits) to permit any behavior on that type that is used in the function body.
Here is the foo function, redefined with a parameterized type. A single function can define
the operation for all numerical types. Explicit bounds must be set for even basic operations,
such as multiply or even copy, in intro_generics.rs:
fn foo<T>(x: T) -> T
where T: std::ops::Mul<Output=T> + Copy
{
x*x
}
[8]
Functional Programming – a Comparison Chapter 1
Here is a trivial function that accepts a function and argument, then calls the function with
the argument, returning the result. Note the trait bound Fn, indicating that the provided
function is a closure. For an object to be callable, it must implement one of the fn, Fn,
FnMut, or FnOnce traits in intro_generics.rs:
fn bar<F,T>(f: F, x: T) -> T
where F: Fn(T) -> T
{
f(x)
}
Functions as values
Functions are nominally the big feature of functional programming. Specifically, functions
as values are the keystone of the whole paradigm. Glossing over much detail, we will also
introduce the term closure here for future reference. A closure is an object that acts as a
function, implementing fn, Fn, FnMut, or FnOnce.
Simple closures can be defined with the built-in closure syntax. This syntax is also
beneficial because the fn, Fn, FnMut, and FnOnce traits are automatically implemented if
permitted. This syntax is great for shorthand manipulation of data.
Here is an iterator over the range 0 to 10, mapped to the squared value. The square
operation is applied using an inline closure definition sent to the map function of the
iterator. The result of this expression will be an iterator. Here is an expression in
intro_functions.rs:
(0..10).map(|x| x*x);
Closures can also have complex bodies with statements if the block syntax is used.
Here is an iterator from 0 to 10, mapped with a complex equation. The closure provided to
map includes a function definition and a variable binding in intro_functions.rs:
(0..10).map(|x| {
fn f(y: u32) -> u32 {
y*y
}
let z = f(x+1) * f(x+2);
z*z
}
[9]
Functional Programming – a Comparison Chapter 1
It is possible to define functions or methods that accept closures as arguments. To use the
closure as a callable function, a bound of Fn, FnMut, or FnOnce must be specified.
fn main()
{
f(|x|{ x*x }, 2);
}
Many parts of the standard library, particularly iterators, encourage heavy use of functions
as arguments.
(0..10).map(|x| x*x)
.inspect(|x|{ println!("value {}", *x) })
.filter(|x| *x<3)
.filter_map(|x| Some(x))
.fold(0, |x,y| x+y);
[ 10 ]
Functional Programming – a Comparison Chapter 1
Iterators
Iterators are a common feature of OOP languages, and Rust supports this concept well.
Rust iterators are also designed with functional programming in mind, allowing
programmers to write more legible code. The specific concept emphasized here is
composability. When iterators can be manipulated, transformed, and combined, the mess
of for loops can be replaced by individual function calls. These examples can be found in
the intro_iterators.rs file. This is depicted in the following table:
[ 11 ]
Functional Programming – a Comparison Chapter 1
Both of these statements can be wrapped in blocks to create an expression along with any
other term. An example for this is the following, in intro_expressions.rs:
let x = {
fn f(x: u32) -> u32 {
x * x
}
let y = f(5);
y * 3
};
This nested format is uncommon in the wild, but it illustrates the permissive nature of Rust
grammar.
Returning to the concept of functional style expressions, the emphasis should always be on
writing legible literate code without much hassle or bloat. When someone else, or you at a
later time, comes to read your code, it should be immediately understandable. Ideally, the
code should document itself. If you find yourself constantly writing code twice, once in
code and again as comments, then you should reconsider how effective your programming
practices really are.
To start with some examples of functional expressions, let's look at an expression that exists
in most languages, the ternary conditional operator. In a normal if statement, the
condition must occupy its own line and thus cannot be used as a sub-expression.
let x;
if true {
x = 1;
} else {
x = 2;
}
With the ternary operator, this assignment can be moved to a single line, shown as follows
in intro_expressions.rs:
let x = if true { 1 } else { 2 };
[ 12 ]
Functional Programming – a Comparison Chapter 1
Almost every statement from OOP in Rust is also an expression—if, for, while, and so
on. One of the more unique expressions to see in Rust that is uncommon in OOP languages
is direct constructor expressions. All Rust types can be instantiated by single expressions.
Constructors are only necessary in specific cases, for example, when an internal field
requires complex initialization. The following is a simple struct and an equivalent tuple
in intro_expressions.rs:
struct MyStruct
{
a: u32,
b: f32,
c: String
}
fn main()
{
MyStruct {
a: 1,
b: 1.0,
c: "".to_string()
};
The following snippet defines a Term as a tagged union of expression options. In the main
function, a Term t is constructed, then matched with a pattern expression. Note the syntax
similarity between the definition of a tagged union and the matching inside of a pattern
expression in intro_expressions.rs:
enum Term
{
TermVal { value: String },
TermVar { symbol: String },
TermApp { f: Box<Term>, x: Box<Term> },
TermAbs { arg: String, body: Box<Term> }
}
fn main()
[ 13 ]
Functional Programming – a Comparison Chapter 1
{
let mut t = Term::TermVar {
symbol: "".to_string()
};
match t {
Term::TermVal { value: v1 } => v1,
Term::TermVar { symbol: v1 } => v1,
Term::TermApp { f: ref v1, x: ref v2 } =>
"TermApp(?,?)".to_string(),
Term::TermAbs { arg: ref mut v1, body: ref mut v2 } =>
"TermAbs(?,?)".to_string()
};
}
In a simple example, data structures that allocate memory will deconstruct automatically
when they go out of scope. No manual memory management is required in
intro_binding.rs:
fn scoped() {
vec![1, 2, 3];
}
[ 14 ]
Functional Programming – a Comparison Chapter 1
In a slightly more complex example, allocated data structures can be passed around as
return values, or referenced, and so on. These exceptions to simple scoping must also be
accounted for in intro_binding.rs:
fn scoped2() -> Vec<u32>
{
vec![1, 2, 3]
}
This usage tracking can get complicated (and undecidable), so Rust has some rules that
restrict when a variable can escape a context. We call this complex rules ownership. It can
be explained with the following code, in intro_binding.rs:
fn scoped3()
{
let v1 = vec![1, 2, 3];
let v2 = v1;
//it is now illegal to reference v1
//ownership has been transferred to v2
}
When it is not possible or desirable to transfer ownership, the clone trait is encouraged to
create a duplicate copy of whatever data is referenced in intro_binding.rs:
fn scoped4()
{
vec![1, 2, 3].clone();
"".to_string().clone();
}
Cloning or copying is not a perfect solution, and comes with a performance overhead. To
make Rust faster, and it is pretty fast, we also have the concept of borrowing. Borrowing is
a mechanism to receive a direct reference to some data with the promise that ownership
will be returned by some specific point. References are indicated by an ampersand.
Consider the following example, in intro_binding.rs:
fn scoped5()
{
fn foo(v1: &Vec<u32>)
{
for v in v1
{
println!("{}", v);
}
}
[ 15 ]
Functional Programming – a Comparison Chapter 1
fn thread1()
{
let v = vec![1, 2, 3];
handle.join().ok();
}
First, programmers may use the traditional combination of locks and atomic references.
This is explained with the following code, in intro_binding.rs:
use std::sync::{Mutex, Arc};
use std::thread;
fn thread2()
{
for _ in 0..10 {
let counter = Arc::clone(&counter);
let handle = thread::spawn(move || {
let mut num = counter.lock().unwrap();
*num += 1;
});
handles.push(handle);
}
[ 16 ]
Functional Programming – a Comparison Chapter 1
Second, channels provide a nice mechanism for message passing and job queuing between
threads. The send trait is also implemented automatically for most objects. Consider the
following code, in intro_binding.rs:
use std::thread;
use std::sync::mpsc::channel;
fn thread3() {
//do work
let v = vec![1, 2, 3];
sender.send(v).unwrap();
});
handle.join().ok();
receiver.recv().unwrap();
}
All of this concurrency is type-safe and compiler-enforced. Use threads as much as you
want, and if you accidentally try to create a race condition or simple deadlock, then the
compiler will stop you. We call this fearless concurrency.
Algebraic datatypes
In addition to structs/objects and functions/methods, Rust functional programming
includes some rich additions to definable types and structures. Tuples provide a shorthand
for defining simple anonymous structs. Enums provide a type-safe approach to unions of
complex data structures with the added bonus of a constructor tag to help in pattern
matching. The standard library has extensive support for generic programming, from base
types to collections. Even the object system traits are a hybrid cross between the OOP
concept of a class and the FP concept of type classes. Functional style lurks around every
corner, and even if you don't seek them in Rust, you will probably find yourself
unknowingly using the features.
[ 17 ]
Functional Programming – a Comparison Chapter 1
The type aliases can be helpful to create shorthand names for complex types. Alternatively,
the newtype struct pattern can be used to create an alias with different non-equivalent
types. Consider the following example, in intro_datatypes.rs:
//alias
type Name = String;
//newtype
struct NewName(String);
A struct, even when parameterized, can be repetitive when used simply to store multiple
values into a single object. This can be seen in intro_datatypes.rs:
struct Data1
{
a: i32,
b: f64,
c: String
}
struct Data2
{
a: u32,
b: String,
c: f64
}
A tuple helps eliminate redundant struct definitions. No prior type definitions are
necessary to use tuples. Consider the following example, in intro_datatypes.rs:
//alias to tuples
type Tuple1 = (i32, f64, String);
type Tuple2 = (u32, String, f64);
//named tuples
struct New1(i32, f64, String);
struct New2(u32, String, f64);
Standard operators can be implemented for any type by implementing the correct
trait. Consider the following example for this, in intro_datatypes.rs:
use std::ops::Mul;
struct Point
{
x: i32,
y: i32
[ 18 ]
Another Random Scribd Document
with Unrelated Content
boatman said was the only thing, and the thing indispensable. I tasted of it—and truly
it had not the usual odious taste of our American whiskey!
Mr. Dewey left New York for England on the 8th June 1833, and
arrived in St. George's channel on the 24th of the same month,
having a fair wind and smooth sea during the entire passage.
Leaving England, he visited Wales, Ireland, Scotland, France,
Belgium, Prussia, Switzerland, and Italy. Returning by way of
Liverpool, he reached home on the 22d of May, 1834.
RICHARDSON'S DICTIONARY.
CA´LEFY
Lat. Calefieri, to be or become hot.
CALEFA´CTION }
Calere, Vossius deduces from the Doric
CALI´DITY
Καλεος for Κηλεος, burning.
CA´LIDUCT
To heat, to be, become, or cause to be hot.
But crystal will calefie into electricity; that is, a power to attract straws or light bodies
and convert the needle freely placed.—Brown. Vulgar Errours, b. ii. c. 1.
As [if] the remembrance of calefaction can warm a man in a cold frosty night.—More.
Philos. Poems, c. 2, Pref.
But ice will dissolve in any way of heat; for it will dissolve with fire; it will colliquate in
water, or warm oyl; nor doth it onely submit unto an actual heat, but not endure the
potential calidity of many waters.—Brown. Vulgar Errours. b. ii. c. 1.
BOOK OF GEMS.
The Book of Gems. The Poets and Artists of Great Britain. Edited by
S. C. Hall. London and New York: Saunders and Otley.
This work combines the rich embellishments of the very best of the
race of Annuals, with a far higher claim to notice than any of them in
its strictly literary department. If we regard this volume as the only
one to appear, the title will convey no idea of the design—but we are
promised a continuation. The whole, if we comprehend, will contain
specimens of all the principal poets and artists of Great Britain. In
the present instance we have the poets as far as Prior, including a
period of about four hundred years, with extracts from Chaucer,
Lydgate, James I, Hawes, Carew, Quarles, Shirley, Habington,
Lovelace, Wyatt, Surrey, Sackville, Vere, Gascoigne, Raleigh,
Spenser, Sidney, Brooke, Southwell, Daniel, Drayton, Shakspeare,
Walton, Davies, Donne, Jonson, Corbet, Phineas Fletcher, Giles
Fletcher, Drummond, Wither, Carew, Browne, Herrick, Quarles,
Herbert, Davenant, Waller, Milton, Suckling, Butler, Crashaw,
Denham, Cowley, Marvell, Dryden, Roscommon, Dorset, Sedley,
Rochester, Sheffield, and Prior. Of these, all the autographs have
been obtained and are published collectively at the end of the book,
with the exception of the nine first mentioned. The work is
illustrated by fifty-three engravings, each by different artists. A sea-
side group by Harding, and L'Allegro and Il Penseroso by Parris, are
particularly good—but all are excellent.
But these verses, however good, do not bear with them much of the
general character of the English antique. Something more of this will
be found in the following lines by Corbet—besides a rich vein of
humor and sarcasm.
Farewell rewards and fairies!
Good housewives now you may say,
For now foul sluts in dairies
Do fare as well as they:
And though they sweep their hearths no less
Than maids were wont to do,
Yet who of late for cleanliness
Finds sixpence in her shoe?
The whole thing is redolent with poetry of the very loftiest order. It
is positively crowded with nature and with pathos. Every line is an
idea—conveying either the beauty and playfulness of the fawn, or
the artlessness of the maiden, or the love of the maiden, or her
admiration, or her grief, or the fragrance and sweet warmth, and
perfect appropriateness of the little nestlike bed of lilies and roses,
which the fawn devoured as it lay upon them, and could scarcely be
distinguished from them by the once happy little damsel who went
to seek her pet with an arch and rosy smile upon her face. Consider
the great variety of truth and delicate thought in the few lines we
have quoted—the wonder of the maiden at the fleetness of her
favorite—the “little silver feet”—the fawn challenging his mistress to
the race, “with a pretty skipping grace,” running on before, and then,
with head turned back, awaiting her approach only to fly from it
again—can we not distinctly perceive all these things? The exceeding
vigor, too, and beauty of the line
which are vividly apparent when we regard the artless nature of the
speaker, and the four feet of the favorite—one for each wind. Then
the garden of “my own,” so overgrown—entangled—with lilies and
roses as to be “a little wilderness”—the fawn loving to be there and
there “only”—the maiden seeking it “where it should lie,” and not
being able to distinguish it from the flowers until “itself would rise”—
the lying among the lilies “like a bank of lilies”—the loving to “fill”
itself with roses,
and these things being its “chief” delights—and then the pre-
eminent beauty and naturalness of the concluding lines—whose very
outrageous hyperbole and absurdity only render them the more true
to nature and to propriety, when we consider the innocence, the
artlessness, the enthusiasm, the passionate grief, and more
passionate admiration of the bereaved child.
SOUTH-SEA EXPEDITION.
“No part of the commerce of this country is more important than that carried on in
the Pacific Ocean. It is large in amount. Not less than $12,000,000 are invested in
and actively employed by one branch of the whale fishery alone; in the whole trade
there is directly and indirectly involved not less than fifty to seventy millions of
property. In like manner from 170 to 200,000 tons of our shipping, and from 9 to
12000 of our seamen are employed, amounting to about one-tenth of the whole
navigation of the Union. Its results are profitable. It is to a great extent not a mere
exchange of commodities, but the creation of wealth by labor from the ocean. The
fisheries alone produce at this time an annual income of from five to six millions of
dollars; and it is not possible to look at Nantucket, New Bedford, New London, Sag
Harbor and a large number of other districts upon our Northern coasts, without the
deep conviction that it is an employment alike beneficial to the moral, political, and
commercial interests of our fellow-citizens.”
“During the circumnavigation of the globe, in which I crossed the equator six times,
and varied my course from 40 deg. North to 57 deg. South latitude, I have never
found myself beyond the limits of our commercial marine. The accounts given of the
dangers and losses to which our ships are exposed by the extension of our trade into
seas but little known, so far, in my opinion from being exaggerated, would admit of
being placed in bolder relief, and the protection of government employed in stronger
terms. I speak from practical knowledge, having myself seen the dangers and
painfully felt the want of the very kind of information which our commercial interests
so much need, and which, I suppose, would be the object of such an expedition as is
now under consideration before the committee of Congress to give.
* * * * *
“The commerce of our country has extended itself to remote parts of the world, is
carried on around islands and reefs not laid down in the charts, among even groups
of islands from ten to sixty in number, abounding in objects valuable in commerce,
but of which nothing is known accurately; no not even the sketch of a harbor has
been made, while of such as are inhabited our knowledge is still more imperfect.”
“To look after our merchant there—to offer him every possible facility—to open new
channels for his enterprise, and to keep up a respectable naval force to protect him—
is only paying a debt we owe to the commerce of the country: for millions have
flowed into the treasury from this source, before one cent was expended for its
protection.”
The intercourse carried on between the Pacific islands and the coast
of China, is highly profitable, the immense returns of the whale
fishery in the ocean which surrounds those islands, and along the
continental coasts, have been already shown. Our whalers have
traversed the wide expanse from Peru and Chili on the west, to the
isles of Japan on the east, gathering national reverence, as well as
individual emolument, in their course; and yet until the late
appropriation, Congress has never yielded them any pecuniary
assistance, leaving their very security to the scientific labors of
countries far more distant, and infinitely less interested, than our
own.
The commercial nations of the earth have done much, and much remains to be
accomplished. We stand a solitary instance among those who are considered
commercial, as never having put forth a particle of strength or expended a dollar of
our money, to add to the accumulated stock of commercial and geographical
knowledge, except in partially exploring our own territory.
When our naval commanders and hardy tars have achieved a victory on the deep,
they have to seek our harbors, and conduct their prizes into port by tables and charts
furnished perhaps by the very people whom they have vanquished.
* * * * *
The exports, and, more emphatically, the imports of the United States, her receipts
and expenditures, are written on every pillar erected by commerce on every sea and
in every clime; but the amount of her subscription stock to erect those pillars and for
the advancement of knowledge is no where to be found.
* * * * *
Have we not then reached a degree of mental strength, which will enable us to find
our way about the globe without leading-strings? Are we forever to take the highway
others have laid out for us, and fixed with mile-stones and guide boards? No: a time
of enterprise and adventure must be at hand, it is already here; and its march is
onward, as certain as a star approaches its zenith.
Surveying and Exploring Expedition to the Pacific Ocean and South Seas.—We learn
that the President has given orders to have the exploring vessels fitted out, with the
least possible delay. The appropriation made by Congress was ample to ensure all the
great objects contemplated by the expedition, and the Executive is determined that
nothing shall be wanting to render the expedition in every respect worthy the
character and great commercial resources of the country.
The frigate Macedonian, now undergoing thorough repairs at Norfolk, two brigs of
two hundred tons each, one or more tenders, and a store ship of competent
dimensions, is, we understand, the force agreed upon, and to be put in a state of
immediate preparation.
Captain Thomas A. C. Jones, an officer possessing many high qualities for such a
service, has been appointed to the command; and officers for the other vessels will
be immediately selected.
The Macedonian has been chosen instead of a sloop of war, on account of the
increased accommodations she will afford the scientific corps, a department the
President has determined shall be complete in its organization, including the ablest
men that can be procured, so that nothing within the whole range of every
department of natural history and philosophy shall be omitted. Not only on this
account has the frigate been selected, but also for the purpose of a more extended
protection of our whalemen and traders; and to impress on the minds of the natives a
just conception of our character, power, and policy. The frequent disturbances and
massacres committed on our seamen by the natives inhabiting the islands in those
distant seas, make this measure the dictate of humanity.
We understand also, that to J. N. Reynolds, Esq. the President has given the
appointment of Corresponding Secretary to the expedition. Between this gentleman
and Captain Jones there is the most friendly feeling and harmony of action. The
cordiality they entertain for each other, we trust will be felt by all, whether citizen or
officer, who shall be so fortunate as to be connected with the expedition.
Thus it will be seen, steps are being taken to remove the reproach of
our country alluded to by Mr. Reynolds, and that that gentleman has
been appointed to the highest civil situation in the expedition; a
station which we know him to be exceedingly well qualified to fill.
The liberality of the appropriation for the enterprise, the strong
interest taken by our energetic chief magistrate in its organization,
the experience and intelligence of the distinguished commander at
its head, all promise well for its successful termination. Our most
cordial good wishes will accompany the adventure, and we trust that
it will prove the germ of a spirit of scientific ambition, which,
fostered by legislative patronage and protection, shall build up for us
a name in nautical discovery commensurate with our moral, political,
and commercial position among the nations of the earth.
ELKSWATAWA.
Our hero is next seen in Kentucky, where we find him, on the night
of the 10th of August 1809, in the woods, on the banks of the Ohio,
in company with one Mr. Earthquake, a hunter. A cry is suddenly
heard proceeding from the river. Stealthily approaching the banks,
Mr. R. and his friend look abroad and discover—nothing. Earthquake,
however, (whom our hero calls Earth for brevity) is of opinion that
the Indians have been murdering some emigrant family. While
deliberating, a light is discovered on the Illinois bank of the river, and
presently a band of Indian warriors become visible. They are
dancing a war-dance, with a parcel of bloody scalps in their hands,
and (credat Judæus!) with Mr. Rolfe's very identical little sweetheart
in their abominable clutches! “Is there a human bosom callous to the
appeals of pity?” here says Mr. Richard Rolfe, attorney at law, placing
his hand upon his heart. Mr. Earthquake, unfortunately, says nothing,
but there can be no doubt in any reasonable mind, that had he
opened his mouth at all, “Humph! here's a pretty kettle of fish!”
would have come out of it.
It appears that Mr. Rolfe having decamped from Petersburg, old Mr.
Foreman, as a necessary consequence, becomes unfortunate in
business, fails, and goes off to Pittsburg—or perhaps goes to
Pittsburg first and then fails—at all events it is incumbent upon him
to emigrate and go down the Ohio in a flat-boat with all his family,
and so down he goes. He arrives, of course, before any accident can
possibly happen to him, exactly opposite the spot where that ill-
treated young attorney, Mr. Rolfe, is sitting as aforesaid, with a very
long face, in the woods. But having got so far, it follows that he can
get no farther. The Indians now catch him—(what business had he
to reject Mr. Rolfe?) they give him a yell—(oh, the old villain!) they
kill him—(quite right!) scalp him, and throw him overboard, him and
all his family, with the exception of the young lady. Her they think it
better to carry across to the Illinois side of the river, and set her up
on the top of a rock just opposite our hero, with a view, no doubt, of
letting that interesting young gentleman behold her to the greatest
possible advantage.
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