Programming in Scala Fifth Edition 5th Edition Martin Odersky Instant Download
Programming in Scala Fifth Edition 5th Edition Martin Odersky Instant Download
https://ebookbell.com/product/programming-in-scala-fifth-
edition-5th-edition-martin-odersky-33360326
https://ebookbell.com/product/programming-in-scala-a-comprehensive-
stepbystep-guide-2nd-edition-2nd-edition-martin-odersky-2544472
https://ebookbell.com/product/programming-in-scala-a-comprehensive-
stepbystep-guide-odersky-m-2598228
Programming In Scala Updated For Scala 212 3rd Edition Martin Odersky
https://ebookbell.com/product/programming-in-scala-updated-for-
scala-212-3rd-edition-martin-odersky-5196380
https://ebookbell.com/product/programming-in-scala-a-comprehensive-
stepbystep-guide-third-edition-martin-odersky-5903268
Functional Programming In Scala Second Edition Meap V08 2nd All
Chapters Available Michael Pilquist
https://ebookbell.com/product/functional-programming-in-scala-second-
edition-meap-v08-2nd-all-chapters-available-michael-pilquist-47503176
https://ebookbell.com/product/functional-programming-in-scala-
meap-v10-paul-chiusano-runar-bjarnason-36703538
https://ebookbell.com/product/functional-programming-in-scala-second-
edition-michael-pilquistpaul-chiusano-rnar-bjarnasson-paul-
chiusano-231980314
https://ebookbell.com/product/learning-concurrent-programming-in-
scala-second-edition-2nd-edition-aleksandar-prokopec-42970064
https://ebookbell.com/product/learning-concurrent-programming-in-
scala-2nd-prokopec-aleksandar-6858126
A comprehensive step-by-step guide
Programming in
Martin Odersky
Lex Spoon
artima Bill Venners
Frank Sommers
Prepared for 138040
Scala language.
- Matthew Todd
The book Programming in Scala is not only about how, but more im-
portantly, why to develop programs in this new programming language. The
book’s pragmatic approach in introducing the power of combining object-
oriented and functional programming leaves the reader without any doubts
as to what Scala really is.
- Dr. Ervin Varga, CEO/founder, EXPRO I.T. Consulting
The book Programming in Scala outright oozes the huge amount of hard
work that has gone into it. I’ve never read a tutorial-style book before that
accomplishes to be introductory yet comprehensive: in their (misguided) at-
tempt to be approachable and not “confuse” the reader, most tutorials silently
ignore aspects of a subject that are too advanced for the current discussion.
This leaves a very bad taste, as one can never be sure as to the understanding
one has achieved. There is always some residual “magic” that hasn’t been
explained and cannot be judged at all by the reader. This book never does
that, it never takes anything for granted: every detail is either sufficiently
explained or a reference to a later explanation is given. Indeed, the text is
extensively cross-referenced and indexed, so that forming a complete picture
of a complex topic is relatively easy.
- Gerald Loeffler, Enterprise Java Architect
artima
Prepared for 138040
A RTIMA P RESS
WALNUT C REEK , C ALIFORNIA
Programming in Scala
Fifth Edition
Martin Odersky is the creator of the Scala language and a professor at EPFL in
Lausanne, Switzerland. Lex Spoon worked on Scala for two years as a post-doc
with Martin Odersky. Bill Venners is president of Artima, Inc. Frank Sommers is
president of Autospaces, Inc.
All information and materials in this book are provided "as is" and without
warranty of any kind.
The term “Artima” and the Artima logo are trademarks or registered trademarks of
Artima, Inc. All other company and/or product names may be trademarks or
registered trademarks of their owners.
Prepared for 138040
Contents xi
Foreword xxix
Acknowledgments xxxiii
Introduction xxxvi
1 A Scalable Language 43
1.1 A language that grows on you . . . . . . . . . . . . . . 44
1.2 What makes Scala scalable? . . . . . . . . . . . . . . . 47
1.3 Why Scala? . . . . . . . . . . . . . . . . . . . . . . . . 51
1.4 Scala’s roots . . . . . . . . . . . . . . . . . . . . . . . 58
1.5 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . 59
11 Traits 234
11.1 How traits work . . . . . . . . . . . . . . . . . . . . . 234
11.2 Thin versus rich interfaces . . . . . . . . . . . . . . . . 237
11.3 Traits as stackable modifications . . . . . . . . . . . . . 239
11.4 Why not multiple inheritance? . . . . . . . . . . . . . . 243
11.5 Trait parameters . . . . . . . . . . . . . . . . . . . . . 248
11.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . 250
19 Enums 416
19.1 Enumerated data types . . . . . . . . . . . . . . . . . . 416
19.2 Algebraic data types . . . . . . . . . . . . . . . . . . . 420
19.3 Generalized ADTs . . . . . . . . . . . . . . . . . . . . 422
19.4 What makes ADTs algebraic . . . . . . . . . . . . . . 423
19.5 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . 427
21 Givens 455
21.1 How it works . . . . . . . . . . . . . . . . . . . . . . . 455
21.2 Parameterized given types . . . . . . . . . . . . . . . . 459
21.3 Anonymous givens . . . . . . . . . . . . . . . . . . . . 464
21.4 Parameterized givens as typeclasses . . . . . . . . . . . 465
21.5 Given imports . . . . . . . . . . . . . . . . . . . . . . 468
21.6 Rules for context parameters . . . . . . . . . . . . . . . 469
21.7 When multiple givens apply . . . . . . . . . . . . . . . 472
21.8 Debugging givens . . . . . . . . . . . . . . . . . . . . 474
21.9 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . 476
23 Typeclasses 493
23.1 Why typeclasses? . . . . . . . . . . . . . . . . . . . . 493
23.2 Context bounds . . . . . . . . . . . . . . . . . . . . . . 498
23.3 Main methods . . . . . . . . . . . . . . . . . . . . . . 501
23.4 Multiversal equality . . . . . . . . . . . . . . . . . . . 505
23.5 Implicit conversions . . . . . . . . . . . . . . . . . . . 511
23.6 Typeclass case study: JSON serialization . . . . . . . . 514
23.7 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . 523
Glossary 601
Bibliography 617
Index 622
Prepared for 138040
xix
Contents xx
xxi
Contents xxii
xxiii
List of Listings xxiv
and Typesafe, later named Lightbend, had recently been formed to support,
1 DOT, or dependent object types, calculus is a series of formalizations attempting to
characterize the essence of Scala’s type system.
ture set, let alone something Scala was designed for. The feature previously-
known as implicits is perhaps the most well-known feature of Scala that has
been exploited to bend Scala 2 in unexpected ways. Example use cases of
Cover · Overview · Contents · Suggest · Glossary · Index
Foreword xxxi
You may have heard the oft-repeated mantra that in many ways, Scala
3 represents a simplification of the Scala that came before it. The story of
implicits is an excellent example. Cognizant of the back flips programmers
were doing with implicits in an attempt to realize broader programming pat-
terns like typeclass derivation, Martin, with the help of many others, came
to the conclusion that we should not focus on implicits as a mechanism for
people to use in the most general case. Rather, we should focus on what
programmers want to do with implicits, and make that easier and more per-
formant. This is where the mantra, “Scala 3 focuses on intent rather than
mechanism,” comes from.
With Scala 3, rather than focus on the generality of implicits as a mech-
anism, the decision was made to focus on specific use-cases that developers
had in mind when choosing to use implicits in the first place, and to make
these patterns more direct to use. Examples include passing context or con-
figuration information to methods implicitly, without the programmer having
to explicitly thread through repetitive arguments; retroactively adding meth-
ods to classes; and converting between types, like Ints and Doubles during
arithmetic. Now, Scala 3 makes these use cases available to programmers
without needing to understand some “deep” intuition about how the Scala
compiler resolves implicits. You can instead just focus on tasks like “add a
method foo to class Bar without having to recompile it.” No PhD required.
Just replace the previous notion of “implicit” with other more direct key-
words that correspond to specific use cases, such as given and using. See
Chapters 21 and 22 for more on this.
This story of “prioritizing intent over mechanism” doesn’t stop at the
revamping of implicits. Rather, the philosophy goes on to touch upon most
every aspect of the language. Examples include additions and streamlining
of many aspects of Scala’s type system, from union types, to enums, to match
types—or even the cleanups to Scala’s syntax: optional braces to improve
readability, and more readable “quiet” syntax for ifs, elses, and whiles,
resulting in conditionals that look much more English-like.
Don’t take my word for it. Whether you’re a newcomer to Scala, or an
experienced Scala developer, I hope you find many of the new design ideas
that have entered Scala 3 to be as refreshing and straightforward as I do!
Prepared for 138040
Heather Miller
Lausanne, Switzerland
June 1, 2021
Many people have contributed to this book and to the material it covers. We
are grateful to all of them.
Scala itself has been a collective effort of many people. The design
and the implementation of version 1.0 was helped by Philippe Altherr, Vin-
cent Cremet, Gilles Dubochet, Burak Emir, Stéphane Micheloud, Nikolay
Mihaylov, Michel Schinz, Erik Stenman, and Matthias Zenger. Phil Bag-
well, Antonio Cunei, Iulian Dragos, Gilles Dubochet, Miguel Garcia, Philipp
Haller, Sean McDirmid, Ingo Maier, Donna Malayeri, Adriaan Moors, Hu-
bert Plociniczak, Paul Phillips, Aleksandar Prokopec, Tiark Rompf, Lukas
Rytz, and Geoffrey Washburn joined in the effort to develop the second and
current version of the language and tools.
Gilad Bracha, Nathan Bronson, Caoyuan, Aemon Cannon, Craig Cham-
bers, Chris Conrad, Erik Ernst, Matthias Felleisen, Mark Harrah, Shriram
Krishnamurti, Gary Leavens, David MacIver, Sebastian Maneth, Rickard
Nilsson, Erik Meijer, Lalit Pant, David Pollak, Jon Pretty, Klaus Ostermann,
Jorge Ortiz, Didier Rémy, Miles Sabin, Vijay Saraswat, Daniel Spiewak,
James Strachan, Don Syme, Erik Torreborre, Mads Torgersen, Philip Wadler,
Jamie Webb, John Williams, Kevin Wright, and Jason Zaugg have shaped the
design of the language by graciously sharing their ideas with us in lively and
inspiring discussions, by contributing important pieces of code to the open
source effort, as well as through comments on previous versions of this doc-
ument. The contributors to the Scala mailing list have also given very useful
feedback that helped us improve the language and its tools.
George Berger has worked tremendously to make the build process and
the web presence for the book work smoothly. As a result this project has
Prepared for 138040
We would also like to thank those who submitted comments and er-
rata after the first two editions were published, including Felix Siegrist,
Lothar Meyer-Lerbs, Diethard Michaelis, Roshan Dawrani, Donn Stephan,
Cover · Overview · Contents · Suggest · Glossary · Index
Acknowledgments xxxv
William Uther, Francisco Reverbel, Jim Balter, and Freek de Bruijn, Am-
brose Laing, Sekhar Prabhala, Levon Saldamli, Andrew Bursavich, Hjal-
mar Peters, Thomas Fehr, Alain O’Dea, Rob Dickens, Tim Taylor, Chris-
tian Sternagel, Michel Parisien, Joel Neely, Brian McKeon, Thomas Fehr,
Joseph Elliott, Gabriel da Silva Ribeiro, Thomas Fehr, Pablo Ripolles, Dou-
glas Gaylor, Kevin Squire, Harry-Anton Talvik, Christopher Simpkins, Mar-
tin Witmann-Funk, Jim Balter, Peter Foster, Craig Bordelon, Heinz-Peter
Gumm, Peter Chapin, Kevin Wright, Ananthan Srinivasan, Omar Kilani,
Donn Stephan, Guenther Waffler.
Lex would like to thank Aaron Abrams, Jason Adams, Henry and Emily
Crutcher, Joey Gibson, Gunnar Hillert, Matthew Link, Toby Reyelts, Jason
Snape, John and Melinda Weathers, and all of the Atlanta Scala Enthusiasts
for many helpful discussions about the language design, its mathematical
underpinnings, and how to present Scala to working engineers.
A special thanks to Dave Briccetti and Adriaan Moors for reviewing the
third edition, and to Marconi Lanna for not only reviewing, but providing
motivation for the third edition by giving a talk entitled “What’s new since
Programming in Scala.”
Bill would like to thank Gary Cornell, Greg Doench, Andy Hunt, Mike
Leonard, Tyler Ortman, Bill Pollock, Dave Thomas, and Adam Wright for
providing insight and advice on book publishing. Bill would also like to
thank Dick Wall for collaborating on our Stairway to Scala course, which
is in great part based on this book. Our many years of experience teaching
Stairway to Scala helped make this book better. Lastly, Bill would like to
thank Darlene Gruendl and Samantha Woolf for their help in getting the
third edition completed.
Finally, we would like to thank Julien Richard-Foy for his work to bring
the fourth edition of this book up to date with Scala 2.13, in particular the
new collections redesign.
Prepared for 138040
This book is a tutorial for the Scala programming language, written by peo-
ple directly involved in the development of Scala. Our goal is that by reading
this book, you can learn everything you need to be a productive Scala pro-
grammer. All examples in this book compile with Scala version 3.0.0.
Because the main purpose of this book is to serve as a tutorial, the recom-
mended way to read this book is in chapter order, from front to back. We
have tried hard to introduce one topic at a time, and explain new topics only
in terms of topics we’ve already introduced. Thus, if you skip to the back
to get an early peek at something, you may find it explained in terms of
concepts you don’t quite understand. To the extent you read the chapters
in order, we think you’ll find it quite straightforward to gain competency in
Scala, one step at a time.
If you see a term you do not know, be sure to check the glossary and
the index. Many readers will skim parts of the book, and that is just fine.
The glossary and index can help you backtrack whenever you skim over
something too quickly.
After you have read the book once, it should also serve as a language
reference. There is a formal specification of the Scala language, but the lan-
guage specification tries for precision at the expense of readability. Although
this book doesn’t cover every detail of Scala, it is quite comprehensive and
should serve as an approachable language reference as you become more
adept at programming in Scala.
EBook features
This book is available in both paper and PDF eBook form. The eBook is not
simply an electronic copy of the paper version of the book. While the content
is the same as in the paper version, the eBook has been carefully designed
and optimized for reading on a computer screen.
The first thing to notice is that most references within the eBook are
hyperlinked. If you select a reference to a chapter, figure, or glossary entry,
your PDF viewer should take you immediately to the selected item so that
you do not have to flip around to find it.
Additionally, at the bottom of each page in the eBook are a number of
navigation links. The Cover, Overview, and Contents links take you to the
front matter of the book. The Glossary and Index links take you to reference
parts of the book. Finally, if you find a typo, or something you think could
be explained better, please click on the Suggest link, which will take you to
an online web application where you can give the authors feedback.
Although the same pages appear in the eBook as in the printed book,
blank pages are removed and the remaining pages renumbered. The pages
are numbered differently so that it is easier for you to determine PDF page
numbers when printing only a portion of the eBook. The pages in the eBook
are, therefore, numbered exactly as your PDF viewer will number them.
Typographic conventions
The first time a term is used, it is italicized. Small code examples, such as
x + 1, are written inline with a mono-spaced font. Larger code examples are
put into mono-spaced quotation blocks like this:
def hello() =
println("Hello, world!")
When interactive shells are shown, responses from the shell are shown in a
lighter font:
scala> 3 + 4
val res0: Int = 7
Prepared for 138040
Content overview
• Chapter 1, “A Scalable Language,” gives an overview of Scala’s design
as well as the reasoning, and history, behind it.
• Chapter 3, “Next Steps in Scala,” shows you several more basic pro-
gramming tasks that will help you get up to speed quickly in Scala.
After completing this chapter, you should be able to start using Scala
for simple scripting tasks.
• Chapter 19, “Enums and ADTs,” introduces twin constructs that sup-
port you when writing regular, non-encapsulated data structures.
• Chapter 14, “Working with Lists,” explains in detail lists, which are
probably the most commonly used data structure in Scala programs.
• Chapter 15, “Working with Other Collections,” shows you how to use
the basic Scala collections, such as lists, arrays, tuples, sets, and maps.
• Chapter 16, “Mutable Objects,” explains mutable objects and the syn-
tax Scala provides to express them. The chapter concludes with a case
study on discrete event simulation, which shows some mutable objects
in action.
• Chapter 21, “Givens,” describes Scala’s feature that helps you work
with contextual parameters to functions. Passing in all contextual in-
formation is simple, but can entail a lot of boilerplate. Givens help you
reduce that boilerplate.
• Chapter 22, “Extension Methods,” describes Scala’s mechanism for
making it appear as if a function is defined as a method on a class,
when it is really defined outside the class.
• Chapter 23, “Typeclasses,” yet to be written, this chapter will illustrate
several examples of typeclasses.
• Chapter 24, “Collections in Depth,” gives a detailed tour of the collec-
tions library.
• Chapter 25, “Assertions and Tests,” shows Scala’s assertion mecha-
nism and gives a tour of several tools available for writing tests in
Scala, focusing on ScalaTest in particular.
Resources
At https://www.scala-lang.org, the main website for Scala, you’ll find
the latest Scala release and links to documentation and community resources.
For a more condensed page of links to Scala resources, visit this book’s web-
site: https://booksites.artima.com/programming_in_scala_5ed.
Source code
You can download a ZIP file containing the source code of this book, which is
released under the Apache 2.0 open source license, from the book’s website:
https://booksites.artima.com/programming_in_scala_5ed.
Errata
Although this book has been heavily reviewed and checked, errors will in-
evitably slip through. For a (hopefully short) list of errata for this book, visit
Prepared for 138040
https://booksites.artima.com/programming_in_scala_5ed/errata.
If you find an error, please report it at the above URL, so that we can fix it in
a future printing or edition of this book.
Cover · Overview · Contents · Suggest · Glossary · Index
Programming in Scala
Fifth Edition
println("Hello, reader!")
Prepared for 138040
A Scalable Language
The name Scala stands for “scalable language.” The language is so named
because it was designed to grow with the demands of its users. You can apply
Scala to a wide range of programming tasks, from writing small scripts to
building large systems.1
Scala is easy to get into. It runs on the standard Java and JavaScript
platforms and interoperates seamlessly with all platform libraries. It’s quite
a good language for writing scripts that pull together existing libraries. But it
can apply its strengths even more when used for building large systems and
frameworks of reusable components.
Technically, Scala is a blend of object-oriented and functional program-
ming concepts in a statically typed language. The fusion of object-oriented
and functional programming shows up in many different aspects of Scala;
it is probably more pervasive than in any other widely used language. The
two programming styles have complementary strengths when it comes to
scalability. Scala’s functional programming constructs make it easy to build
interesting things quickly from simple parts. Its object-oriented constructs
make it easy to structure larger systems and adapt them to new demands.
The combination of both styles in Scala makes it possible to express new
kinds of programming patterns and component abstractions. It also leads to
a legible and concise programming style. And because it is so malleable,
programming in Scala can be a lot of fun.
This initial chapter answers the question, “Why Scala?” It gives a high-
level view of Scala’s design and the reasoning behind it. After reading the
Prepared for 138040
chapter you should have a basic feel for what Scala is and what kinds of
1 Scala is pronounced skah-lah.
tasks it might help you accomplish. Although this book is a Scala tutorial,
this chapter isn’t really part of the tutorial. If you’re eager to start writing
some Scala code, you should jump ahead to Chapter 2.
println(capital("France"))
This program sets up a map from countries to their capitals, modifies the map
by adding a new binding ("Japan" -> "Tokyo"), and prints the capital asso-
ciated with the country France.2 The notation in this example is high level, to
the point, and not cluttered with extraneous semicolons or type annotations.
Indeed, the feel is that of a modern “scripting” language like Perl, Python, or
Ruby. One common characteristic of these languages, which is relevant for
the example above, is that they each support an “associative map” construct
in the syntax of the language.
Associative maps are very useful because they help keep programs leg-
ible and concise, but sometimes you might not agree with their “one size
fits all” philosophy because you need to control the properties of the maps
you use in your program in a more fine-grained way. Scala gives you this
fine-grained control if you need it, because maps in Scala are not language
syntax. They are library abstractions that you can extend and adapt.
In the above program, you’ll get a default Map implementation, but you
can easily change that. You could for example specify a particular implemen-
tation, such as a HashMap or a TreeMap, or with Scala’s parallel collections
module, invoke the par method to obtain a ParMap that executes operations
in parallel. You could specify a default value for the map, or you could over-
ride any other method of the map you create. In each case, you can use the
same easy access syntax for maps as in the example above.
Prepared for 138040
2 Pleasebear with us if you don’t understand all the details of this program. They will be
explained in the next two chapters.
This example shows that Scala can give you both convenience and flex-
ibility. Scala has a set of convenient constructs that help you get started
quickly and let you program in a pleasantly concise style. At the same time,
you have the assurance that you will not outgrow the language. You can al-
ways tailor the program to your requirements, because everything is based
on library modules that you can select and adapt as needed.
265252859812191058636308480000000
BigInt looks like a built-in type because you can use integer literals and
operators such as * and - with values of that type. Yet it is just a class that
3 Raymond, The Cathedral and the Bazaar. [Ray99]
Prepared for 138040
import java.math.BigInteger
6 Scala comes with a standard library, some of which will be covered in this book. For
more information, you can also consult the library’s Scaladoc documentation, which is avail-
able in the distribution and online at http://www.scala-lang.org.
Scala is object-oriented
Object-oriented programming has been immensely successful. Starting from
Simula in the mid-60s and Smalltalk in the 70s, it is now available in more
languages than not. In some domains, objects have taken over completely.
While there is not a precise definition of what object-oriented means, there
is clearly something about objects that appeals to programmers.
In principle, the motivation for object-oriented programming is very sim-
ple: all but the most trivial programs need some sort of structure. The most
straightforward way to do this is to put data and operations into some form of
containers. The great idea of object-oriented programming is to make these
containers fully general, so that they can contain operations as well as data,
and that they are themselves values that can be stored in other containers, or
passed as parameters to operations. Such containers are called objects. Alan
Kay, the inventor of Smalltalk, remarked that in this way the simplest object
has the same construction principle as a full computer: it combines data with
operations under a formalized interface.7 So objects have a lot to do with
language scalability: the same techniques apply to the construction of small
as well as large programs.
Even though object-oriented programming has been mainstream for a
long time, there are relatively few languages that have followed Smalltalk
in pushing this construction principle to its logical conclusion. For instance,
many languages admit values that are not objects, such as the primitive val-
ues in Java. Or they allow static fields and methods that are not members
of any object. These deviations from the pure idea of object-oriented pro-
gramming look quite harmless at first, but they have an annoying tendency
to complicate things and limit scalability.
By contrast, Scala is an object-oriented language in pure form: every
value is an object and every operation is a method call. For example, when
you say 1 + 2 in Scala, you are actually invoking a method named + defined
in class Int. You can define methods with operator-like names that clients
of your API can then use in operator notation.
Prepared for 138040
Scala is more advanced than most other languages when it comes to com-
posing objects. An example is Scala’s traits. Traits are like interfaces in Java,
7 Kay, “The Early History of Smalltalk.” [Kay96]
but they can also have method implementations and even fields.8 Objects are
constructed by mixin composition, which takes the members of a class and
adds the members of a number of traits to them. In this way, different as-
pects of classes can be encapsulated in different traits. This looks a bit like
multiple inheritance, but differs when it comes to the details. Unlike a class,
a trait can add some new functionality to an unspecified superclass. This
makes traits more “pluggable” than classes. In particular, it avoids the clas-
sical “diamond inheritance” problems of multiple inheritance, which arise
when the same class is inherited via several different paths.
Scala is functional
In addition to being a pure object-oriented language, Scala is also a full-
blown functional language. The ideas of functional programming are older
than (electronic) computers. Their foundation was laid in Alonzo Church’s
lambda calculus, which he developed in the 1930s. The first functional pro-
gramming language was Lisp, which dates from the late 50s. Other popular
functional languages are Scheme, SML, Erlang, Haskell, OCaml, and F#.
For a long time, functional programming has been a bit on the sidelines—
popular in academia, but not that widely used in industry. However, in re-
cent years, there has been an increased interest in functional programming
languages and techniques.
Functional programming is guided by two main ideas. The first idea is
that functions are first-class values. In a functional language, a function is a
value of the same status as, say, an integer or a string. You can pass func-
tions as arguments to other functions, return them as results from functions,
or store them in variables. You can also define a function inside another
function, just as you can define an integer value inside a function. And you
can define functions without giving them a name, sprinkling your code with
function literals as easily as you might write integer literals like 42.
Functions that are first-class values provide a convenient means for ab-
stracting over operations and creating new control structures. This general-
ization of functions provides great expressiveness, which often leads to very
legible and concise programs. It also plays an important role for scalability.
As an example, the ScalaTest testing library offers an eventually construct
Prepared for 138040
val xs = 1 to 3
val it = xs.iterator
eventually { it.next() shouldBe 3 }
ative style, which is what programming with mutable data and side effects
is called. But Scala generally makes it easy to avoid imperative constructs
when you want because good functional alternatives exist.
Between 1827 and 1872 one hundred and fifty-eight editions had
issued from the press, and it has been largely reprinted since. The
author, so far from taking pride in his widespread reputation,
seemed all his life long to wish to disconnect his name with the
book, and “as if he would rather it had been the work of some one
else than himself.” This feeling arose from no false modesty. It was
because he knew that in these poems he had painted his own heart,
the best part of it; and he doubted whether it was right thus to
exhibit himself, and by the revelation of only his better self, to win
the good opinion of the world.
Towards the close of 1831 Keble was elected to fill the chair of the
poetry professorship in Oxford, as successor to his friend and
admirer, Dean Milman. This chair he occupied for ten eventful years.
He delivered a series of lectures, clothed in excellent idiomatic Latin
(as was the rule), in which he expounded a theory of poetry which
was original and suggestive. He looked on poetry as a vent for
overcharged feeling, or a full imagination, or some imaginative
regret, which had not found their natural outlet in life and action.
This suggested to him a distinction between what he called primary
and secondary poets—the first employing poetry to relieve their own
hearts, the second, poetic artists, composing poetry from some
other and less impulsive motive. Of the former kind were Homer,
Lucretius, Burns, Scott; of the latter were Euripides, Dryden, Milton.
This view was set forth in an article contributed to the British Critic
in 1838 on the life of Scott, and was more fully developed in two
volumes of Praelectiones Academicae.
His regular visits to Oxford kept him in intercourse with his old
friends in Oriel common room, and made him familiar with the
currents of feeling which swayed the university. Catholic
emancipation and the Reform Bill had deeply stirred, not only the
political spirit of Oxford, but also the church feeling which had long
been stagnant. Cardinal Newman writes, “On Sunday July 14, 1833,
Mr Keble preached the assize sermon in the University pulpit. It was
published under the title of National Apostasy. I have ever
considered and kept the day as the start of the religious movement
of 1833.” The occasion of this sermon was the suppression, by Earl
Grey’s Reform ministry, of ten Irish bishoprics. Against the spirit
which would treat the church as the mere creature of the state Keble
had long chafed inwardly, and now he made his outward protest,
asserting the claim of the church to a heavenly origin and a divine
prerogative. About the same time, and partly stimulated by Keble’s
sermon, some leading spirits in Oxford and elsewhere began a
concerted and systematic course of action to revive High Church
principles and the ancient patristic theology, and by these means
both to defend the church against the assaults of its enemies, and
also to raise to a higher tone the standard of Christian life in
England. This design embodied itself in the Tractarian movement, a
name it received from the famous Tracts for the Times, which were
the vehicle for promulgating the new doctrines. If Keble is to be
reckoned, as Newman would have it, as the primary author of the
movement, it was from Pusey that it received one of its best known
names, and in Newman that it soon found its genuine leader. To the
tracts Keble made only four contributions:—No. 4, containing an
argument, in the manner of Bishop Butler, to show that adherence to
apostolical succession is the safest course; No. 13, which explains
the principle on which the Sunday lessons in the church service are
selected; No. 40, on marriage with one who is unbaptized; No. 89,
on the mysticism attributed to the early fathers of the church.
Besides these contributions from his own pen, he did much for the
series by suggesting subjects, by reviewing tracts written by others,
and by lending to their circulation the weight of his personal
influence.
In 1835 Keble’s father died at the age of ninety, and soon after
this his son married Miss Clarke, left Fairford, and settled at Hursley
vicarage in Hampshire, a living to which he had been presented by
his friend and attached pupil, Sir William Heathcote, and which
continued to be Keble’s home and cure for the remainder of his life.
In the late autumn of the latter year, Keble left Hursley for the
sake of his wife’s health, and sought the milder climate of
Bournemouth. There he had an attack of paralysis, from which he
died on the 29th of March 1866. He was buried in his own
churchyard at Hursley; and in little more than a month his wife was
laid by her husband’s side.
Keene, who never had any regular art training, was essentially
an artists’ artist. He holds the foremost place amongst English
craftsmen in black and white, though his work has never been
appreciated at its real value by the general public. No doubt the
main reason for this lack of public recognition was his
unconventionality. He drew his models exactly as he saw them,
not as he knew the world wanted to see them. He found enough
beauty and romance in all that was around him, and, in his
Punch work, enough subtle humour in nature seized at her most
humorous moments to satisfy him. He never required his models
to grin through a horse collar, as Gillray did, or to put on their
company manners, as was du Maurier’s wont. But Keene was
not only a brilliant worker in pen and ink. As an etcher he has
also to be reckoned with, notwithstanding the fact that his plates
numbered not more than fifty at the outside. Impressions of
them are exceedingly rare, and hardly half a dozen of the plates
are now known to be in existence. He himself regarded them
only as experiments in a difficult but fascinating medium. But in
the opinion of the expert they suffice to place him among the
best etchers of the 19th century. Apart from the etched
frontispieces to some of the Punch pocket-books, only three,
and these by no means the best, have been published. Writing
in L’Artiste for May 1891 of a few which he had seen,
Bracquemond says: “By the freedom, the largeness of their
drawing and execution, these plates must be classed amongst
modern etchings of the first rank.” A few impressions are in the
British Museum, but in the main they were given away to friends
and lie hidden in the albums of the collector.
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
ebookbell.com