An introduction to programming in emacs lisp 2nd Edition Robert J. Chassell - Instantly access the full ebook content in just a few seconds
An introduction to programming in emacs lisp 2nd Edition Robert J. Chassell - Instantly access the full ebook content in just a few seconds
https://ebookultra.com/download/an-introduction-to-programming-using-
alice-2-2-2nd-edition-charles-w-herbert/
https://ebookultra.com/download/an-introduction-to-stata-
programming-1st-edition-christopher-f-baum/
https://ebookultra.com/download/common-lisp-a-gentle-introduction-to-
symbolic-computation-david-s-touretzky/
https://ebookultra.com/download/introduction-to-computing-and-
programming-in-python-a-multimedia-approach-mark-j-guzdial/
Python Programming An Introduction to Computer Science
John M. Zelle
https://ebookultra.com/download/python-programming-an-introduction-to-
computer-science-john-m-zelle/
https://ebookultra.com/download/c-programming-an-introduction-rajiv-
chopra/
https://ebookultra.com/download/programming-concepts-in-c-2nd-edition-
robert-burns/
https://ebookultra.com/download/an-introduction-to-property-law-in-
australia-third-edition-edition-robert-chambers/
https://ebookultra.com/download/an-introduction-to-international-
criminal-law-and-procedure-robert-cryer/
An introduction to programming in emacs lisp 2nd
Edition Robert J. Chassell Digital Instant Download
Author(s): Robert J. Chassell
ISBN(s): 9781882114436, 1882114434
Edition: 2nd
File Details: PDF, 1.06 MB
Year: 2001
Language: english
An Introduction to
by Robert J. Chassell
Copyright c 1990, 1991, 1992, 1993, 1994, 1995, 1997, 2001, 2002 Free
Software Foundation, Inc.
Short Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
1 List Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Practicing Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3 How To Write Function Definitions . . . . . . . . . . . . . . . . . . 29
4 A Few Buffer–Related Functions . . . . . . . . . . . . . . . . . . . . 51
5 A Few More Complex Functions . . . . . . . . . . . . . . . . . . . . 63
6 Narrowing and Widening . . . . . . . . . . . . . . . . . . . . . . . . . 77
7 car, cdr, cons: Fundamental Functions . . . . . . . . . . . . . 81
8 Cutting and Storing Text . . . . . . . . . . . . . . . . . . . . . . . . . 89
9 How Lists are Implemented . . . . . . . . . . . . . . . . . . . . . . . 113
10 Yanking Text Back . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
11 Loops and Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
12 Regular Expression Searches . . . . . . . . . . . . . . . . . . . . . . 149
13 Counting: Repetition and Regexps . . . . . . . . . . . . . . . . . . 167
14 Counting Words in a defun . . . . . . . . . . . . . . . . . . . . . . 181
15 Readying a Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
16 Your ‘.emacs’ File . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
17 Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
18 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Appendix A The the-the Function . . . . . . . . . . . . . . . . . . 241
Appendix B Handling the Kill Ring . . . . . . . . . . . . . . . . . . . 243
Appendix C A Graph with Labelled Axes . . . . . . . . . . . . . . . 255
Appendix D GNU Free Documentation License . . . . . . . . . . . 279
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
ii
iii
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
On Reading this Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
For Whom This is Written. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xii
Lisp History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
A Note for Novices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Thank You . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiv
1 List Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Lisp Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.1 Lisp Atoms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.2 Whitespace in Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1.3 GNU Emacs Helps You Type Lists . . . . . . . . . . . . . . . 3
1.2 Run a Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3 Generate an Error Message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4 Symbol Names and Function Definitions . . . . . . . . . . . . . . . . . . 6
1.5 The Lisp Interpreter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.5.1 Byte Compiling. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.6 Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.6.1 Evaluating Inner Lists . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.7 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.7.1 Error Message for a Symbol Without a Function . . 11
1.7.2 Error Message for a Symbol Without a Value . . . . 11
1.8 Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.8.1 Arguments’ Data Types . . . . . . . . . . . . . . . . . . . . . . . . 13
1.8.2 An Argument as the Value of a Variable or List . . 13
1.8.3 Variable Number of Arguments . . . . . . . . . . . . . . . . . 14
1.8.4 Using the Wrong Type Object as an Argument . . 14
1.8.5 The message Function . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.9 Setting the Value of a Variable . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.9.1 Using set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.9.2 Using setq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1.9.3 Counting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.11 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2 Practicing Evaluation . . . . . . . . . . . . . . . . . . . . . 23
2.1 Buffer Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.2 Getting Buffers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.3 Switching Buffers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.4 Buffer Size and the Location of Point . . . . . . . . . . . . . . . . . . . . 27
2.5 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
iv
17 Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
17.1 debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
17.2 debug-on-entry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
17.3 debug-on-quit and (debug). . . . . . . . . . . . . . . . . . . . . . . . . . 234
17.4 The edebug Source Level Debugger . . . . . . . . . . . . . . . . . . . . 235
17.5 Debugging Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
ix
18 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
x
On Reading this Text xi
Preface
Most of the GNU Emacs integrated environment is written in the pro-
gramming language called Emacs Lisp. The code written in this program-
ming language is the software—the sets of instructions—that tell the com-
puter what to do when you give it commands. Emacs is designed so that
you can write new code in Emacs Lisp and easily install it as an extension
to the editor.
(GNU Emacs is sometimes called an “extensible editor”, but it does much
more than provide editing capabilities. It is better to refer to Emacs as
an “extensible computing environment”. However, that phrase is quite a
mouthful. It is easier to refer to Emacs simply as an editor. Moreover,
everything you do in Emacs—find the Mayan date and phases of the moon,
simplify polynomials, debug code, manage files, read letters, write books—all
these activities are kinds of editing in the most general sense of the word.)
Although Emacs Lisp is usually thought of in association only with
Emacs, it is a full computer programming language. You can use Emacs
Lisp as you would any other programming language.
Perhaps you want to understand programming; perhaps you want to ex-
tend Emacs; or perhaps you want to become a programmer. This introduc-
tion to Emacs Lisp is designed to get you started: to guide you in learning
the fundamentals of programming, and more importantly, to show you how
you can teach yourself to go further.
Lisp History
Lisp was first developed in the late 1950s at the Massachusetts Institute
of Technology for research in artificial intelligence. The great power of the
Lisp language makes it superior for other purposes as well, such as writing
editor commands and integrated environments.
GNU Emacs Lisp is largely inspired by Maclisp, which was written at
MIT in the 1960s. It is somewhat inspired by Common Lisp, which became
a standard in the 1980s. However, Emacs Lisp is much simpler than Common
Lisp. (The standard Emacs distribution contains an optional extensions file,
‘cl.el’, that adds many Common Lisp features to Emacs Lisp.)
In addition to typing a lone keychord, you can prefix what you type with
C-u, which is called the ‘universal argument’. The C-u keychord passes an
argument to the subsequent command. Thus, to indent a region of plain
text by 6 spaces, mark the region, and then type C-u 6 M-C-\. (If you do
not specify a number, Emacs either passes the number 4 to the command
or otherwise runs the command differently than it would otherwise.) See
section “Numeric Arguments” in The GNU Emacs Manual.
If you are reading this in Info using GNU Emacs, you can read through
this whole document just by pressing the space bar, hSPCi. (To learn about
Info, type C-h i and then select Info.)
A note on terminology: when I use the word Lisp alone, I often am
referring to the various dialects of Lisp in general, but when I speak of
Emacs Lisp, I am referring to GNU Emacs Lisp in particular.
Thank You
My thanks to all who helped me with this book. My especial thanks to
Jim Blandy, Noah Friedman, Jim Kingdon, Roland McGrath, Frank Ritter,
Randy Smith, Richard M. Stallman, and Melissa Weisshaus. My thanks
also go to both Philip Johnson and David Stampe for their patient encour-
agement. My mistakes are my own.
Robert J. Chassell
Lisp Atoms 1
1 List Processing
To the untutored eye, Lisp is a strange programming language. In Lisp
code there are parentheses everywhere. Some people even claim that the
name stands for ‘Lots of Isolated Silly Parentheses’. But the claim is un-
warranted. Lisp stands for LISt Processing, and the programming language
handles lists (and lists of lists) by putting them between parentheses. The
parentheses mark the boundaries of the list. Sometimes a list is preceded by
a single apostrophe or quotation mark, ‘’’. Lists are the basis of Lisp.
‘+’. On the other hand, unlike an atom, a list can be split into parts. (See
Chapter 7, “car cdr & cons Fundamental Functions”, page 81.)
In a list, atoms are separated from each other by whitespace. They can
be right next to a parenthesis.
The printed representation of both atoms and lists are called symbolic
expressions or, more concisely, s-expressions. The word expression by itself
can refer to either the printed representation, or to the atom or list as it
is held internally in the computer. Often, people use the term expression
indiscriminately. (Also, in many texts, the word form is used as a synonym
for expression.)
Incidentally, the atoms that make up our universe were named such when
they were thought to be indivisible; but it has been found that physical atoms
are not indivisible. Parts can split off an atom or it can fission into two parts
of roughly equal size. Physical atoms were named prematurely, before their
truer nature was found. In Lisp, certain kinds of atom, such as an array, can
be separated into parts; but the mechanism for doing this is different from
the mechanism for splitting a list. As far as list operations are concerned,
the atoms of a list are unsplittable.
There are many kinds of atom in nature but only a few in Lisp: for
example, numbers, such as 37, 511, or 1729, and symbols, such as ‘+’, ‘foo’,
or ‘forward-line’. The words we have listed in the examples above are
all symbols. In everyday Lisp conversation, the word “atom” is not often
used, because programmers usually try to be more specific about what kind
of atom they are dealing with. Lisp programming is mostly about symbols
(and sometimes numbers) within lists. (Incidentally, the preceding three
word parenthetical remark is a proper list in Lisp, since it consists of atoms,
which in this case are symbols, separated by whitespace and enclosed by
parentheses, without any non-Lisp punctuation.)
Other documents randomly have
different content
Hence, the policy of Campaign of that army superior in Numbers,
is:
Incessantly to proffer battles which:
PRINCIPLE
All else being equal the advantage of Numbers is decisive of victory
in battle and Campaign.
“It is only the force brought into action that avails in battles
and campaigns—the rest does not count.”—Napoleon.
I. In Contact.
II. In Presence.
III. At Distance.
PRINCIPLE
In Strategetics there is but a single method whereby Opportunity
may be availed of, and that is by so augmenting kindred
advantages and so depreciating adverse advantages as to
acquire for the kindred army that particular advantage of
Strategetic means which in the given situation is the proper
basis of the Strategetic movement next in sequence.
At Distance.
The chief requisite for success when acting against an adverse army
at Distance, is the advantage in MOBILITY.
The primary process is that of a Grand Manoeuvre against an
adverse army acting in the formation by Grand Columns, and the
object of such Grand Manoeuvre always is, by superior celerity of
movement, to occupy:
In Presence.
In Contact.
The chief requisite for success when acting offensively against an
adverse Grand Column, or Wing, or Corps d’armee, in Contact,
is the advantage in NUMBERS.
PRINCIPLE
Utilize advantage in Prime Strategetic Means to obtain the
superiority in Numbers at the Point of Contact in an Offensive
Battle; and to nullify the adverse superiority in Numbers at the
point of contact in a Defensive Battle.
Between War and Chess there is a seeming incongruity, which is
the basis of that doubt of the utility of Chess-play, so commonly held
by laymen, and which fallacy few, even among proficients, are
competent to combat.
This doubt most frequently is voiced by the query:
If Chess and War are analagous, why was not
Napoleon a Master Chess-player and Morphy a great
military Commander?
This query readily is answered in the words of Frederic the Great,
viz.:
“To be possessed of talent is not sufficient.
Opportunity to display such talent and to its full extent
is necessary. All depends on the time in which we live.”
The Strategetic talent possessed in common by Morphy and
Napoleon, in both was brought to perfection by long and expert
training.
But circumstances placed the twelve year old Napoleon in the
midst of soldiers and in an era of war, while circumstances placed
the twelve year old Morphy in the midst of Chess-players and in an
era of Peace.
Napoleon was educated a General; Morphy was educated a lawyer.
To develop his self-evident and superlative Strategetic talent,
Napoleon’s education was of the best; to develop his self-evident
and superlative Strategetic talent, Morphy’s education was of the
worst.
Napoleon succeeded as a General; Morphy failed as a lawyer.
The innate capability of Napoleon for Strategetics was developed
in the direction of Warfare; the innate capability of Morphy for
Strategetics was developed in the direction of Chess-play.
In War, Napoleon is superlative; in Chess, Morphy is superlative.
Educated in the law, Napoleon might have proved like Morphy a
non-entity; educated in Chess, Napoleon might have proved like
Morphy a phenomenon.
Educated in War, Morphy might have rivalled Napoleon.
For the Chess-play of Morphy displays that perfect comprehension
of Strategetics, to which none but the great Captains in warfare have
attained.
Perfection in Strategetics consists in exactly interpreting in battle
and campaign, the System of Warfare invented by Epaminondas.
Those able to do this in War have achieved greatness, and the
great at Chess-play are those who best have imitated that exactness
with which Morphy employed this system on the Chess-board.
To those who imagine that Strategetic talent, as exemplified in
Warfare, is different from Strategetic talent as exemplified in Chess-
play, the following may afford matter for reflection.
(First Phase.)
In the consideration of every Strategetic Situation possible in
Warfare, or in Chess-play, the initial process always is a Grand
Reconnaissance.
Grand Reconnaissance is that exact scrutiny of existing conditions,
whereby is determined the relative advantages and disadvantages
possessed by the opposing armies in:
1. Time.
2. Numbers.
3. Position.
4. Organization.
5. Mobility.
6. Topography.
PRINCIPLE
As the advantage in Time gives the right to MOVE and the
advantage in Numbers indicates the MOTIF of movement; so
does the advantage in Position, as expressed by the Strategic
Syllogism, specify the DIRECTION of that movement which
normally appertains to the army having the advantage in Time.
The proper direction of that movement which normally appertains
to the advantage in Time always is indicated by the plus signs in the
Strategic Syllogism, viz.:
THEOREM
Given the Normal ability to move, to determine the Normal motif and
direction of movement.
EXAMPLE
EXPANDED
TACTICO-LOGISTIC INEQUALITY
The Tactico-Logistic Inequality is the algebraic expression of the
relative advantages and disadvantages in Time and in Numbers
appertaining to opposing Strategetic Entireties.
Such advantages and disadvantages are denoted by the terms,
viz.:
1. +T+N
-T-N
2. +T=N
-T=N
3. +T-N
-T+N
4. -T+N
+T-N
5. -T=N
+T=N
6. -T-N
+T+N
RULE
1. Set down in parenthesis those terms of the Strategic Syllogism
which appertain to White.
Set down in parenthesis those terms of the Tactico-Logistic
Inequality which appertain to White.
Connect the two kindred terms thus constructed, by the sign of
addition, to show that each is to augment the other, and superscore
all by the same vincula to show that all are to be taken together to
form one side of the resulting equation.
2. Repeat this process for the Black terms to construct the second
side of the Initial Strategetic Equation, and separate the White from
the Black terms by a minus sign.
STRATEGETIC VALUES
The Strategetic Values of the terms contained in the Strategic
Syllogism and in the Tactico-Logistic Inequality are shown by the
appended tables, viz.:
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.
ebookultra.com