Preface |
|
xiii | |
Part I. Starting with the Basics |
|
|
|
3 | (12) |
|
|
3 | (1) |
|
|
4 | (2) |
|
|
6 | (1) |
|
|
6 | (1) |
|
|
7 | (3) |
|
Formal and Natural Languages |
|
|
10 | (1) |
|
|
11 | (1) |
|
|
12 | (2) |
|
|
14 | (1) |
|
2 Variables, Expressions, and Statements |
|
|
15 | (16) |
|
|
15 | (2) |
|
|
17 | (2) |
|
Expressions and Statements |
|
|
19 | (2) |
|
|
21 | (1) |
|
|
22 | (1) |
|
|
23 | (1) |
|
|
24 | (1) |
|
|
25 | (1) |
|
|
25 | (1) |
|
|
26 | (2) |
|
|
28 | (3) |
|
|
31 | (24) |
|
|
31 | (3) |
|
|
34 | (1) |
|
|
34 | (2) |
|
|
36 | (1) |
|
Adding New Functions (a.k.a. Subroutines) |
|
|
37 | (2) |
|
|
39 | (1) |
|
|
39 | (1) |
|
|
40 | (1) |
|
Variables and Parameters Are Local |
|
|
41 | (1) |
|
|
42 | (1) |
|
Fruitful Functions and Void Functions |
|
|
42 | (2) |
|
|
44 | (2) |
|
Immutable and Mutable Parameters |
|
|
46 | (1) |
|
Functions and Subroutines as First-Class Citizens |
|
|
47 | (2) |
|
Why Functions and Subroutines? |
|
|
49 | (1) |
|
|
50 | (1) |
|
|
50 | (3) |
|
|
53 | (2) |
|
4 Loops, Conditionals, and Recursion |
|
|
55 | (22) |
|
Integer Division and Modulo |
|
|
55 | (1) |
|
|
56 | (2) |
|
|
58 | (2) |
|
|
60 | (1) |
|
|
61 | (1) |
|
|
61 | (1) |
|
|
62 | (1) |
|
if Conditionals as Statement Modifiers |
|
|
63 | (1) |
|
Unless Conditional Statement |
|
|
63 | (1) |
|
|
64 | (2) |
|
|
66 | (1) |
|
Stack Diagrams for Recursive Subroutines |
|
|
67 | (1) |
|
|
68 | (1) |
|
|
68 | (1) |
|
Program Arguments and the MAIN Subroutine |
|
|
69 | (1) |
|
|
70 | (1) |
|
|
71 | (2) |
|
|
73 | (4) |
|
|
77 | (18) |
|
|
77 | (2) |
|
|
79 | (2) |
|
|
81 | (1) |
|
|
82 | (1) |
|
A Complete Programming Language |
|
|
83 | (1) |
|
|
84 | (2) |
|
|
86 | (1) |
|
|
87 | (1) |
|
|
87 | (2) |
|
|
89 | (1) |
|
|
90 | (1) |
|
|
91 | (1) |
|
|
92 | (3) |
|
|
95 | (14) |
|
Assignment Versus Equality |
|
|
95 | (1) |
|
|
96 | (1) |
|
|
96 | (1) |
|
|
97 | (2) |
|
Local Variables and Variable Scoping |
|
|
99 | (3) |
|
Control Flow Statements (last, next, etc.) |
|
|
102 | (2) |
|
|
104 | (2) |
|
|
106 | (1) |
|
|
106 | (1) |
|
|
107 | (1) |
|
|
107 | (2) |
|
|
109 | (30) |
|
|
109 | (1) |
|
|
110 | (5) |
|
|
110 | (1) |
|
Searching for a Substring Within the String |
|
|
111 | (1) |
|
Extracting a Substring from a String |
|
|
111 | (1) |
|
A Few Other Useful String Functions or Methods |
|
|
112 | (3) |
|
String Traversal with a while or for Loop |
|
|
115 | (1) |
|
|
116 | (1) |
|
Regular Expressions (Regexes) |
|
|
116 | (2) |
|
|
118 | (1) |
|
Building your Regex Patterns |
|
|
119 | (8) |
|
|
119 | (1) |
|
Wildcards and Character Classes |
|
|
120 | (1) |
|
|
121 | (1) |
|
|
122 | (2) |
|
|
124 | (1) |
|
|
124 | (1) |
|
Adverbs (a.k.a. Modifiers) |
|
|
125 | (1) |
|
|
126 | (1) |
|
|
127 | (3) |
|
|
127 | (1) |
|
|
128 | (2) |
|
|
130 | (1) |
|
|
130 | (1) |
|
The s/search/replace/ Construct |
|
|
130 | (1) |
|
|
131 | (1) |
|
|
131 | (1) |
|
|
131 | (3) |
|
|
134 | (1) |
|
|
135 | (4) |
|
|
139 | (14) |
|
Reading from and Writing to Files |
|
|
139 | (2) |
|
|
141 | (1) |
|
|
142 | (1) |
|
|
143 | (6) |
|
Words Longer Than 20 Characters (Solution) |
|
|
143 | (1) |
|
Words with No "e" (Solution) |
|
|
144 | (1) |
|
Avoiding Other Letters (Solution) |
|
|
145 | (1) |
|
Using Only Some Letters (Solution) |
|
|
146 | (1) |
|
Using All Letters of a List (Solution) |
|
|
147 | (1) |
|
Alphabetic Order (Solution) |
|
|
147 | (1) |
|
Another Example of Reduction to a Previously Solved Problem |
|
|
148 | (1) |
|
|
149 | (1) |
|
|
149 | (1) |
|
|
150 | (3) |
|
|
153 | (30) |
|
Lists and Arrays Are Sequences |
|
|
153 | (2) |
|
|
155 | (3) |
|
Adding New Elements to an Array or Removing Some |
|
|
158 | (1) |
|
|
159 | (1) |
|
Other Ways to Modify an Array |
|
|
160 | (2) |
|
|
162 | (2) |
|
|
164 | (1) |
|
|
165 | (5) |
|
Reducing a List to a Value |
|
|
165 | (1) |
|
The Reduction Metaoperator |
|
|
166 | (1) |
|
Mapping a List to Another List |
|
|
167 | (1) |
|
Filtering the Elements of a List |
|
|
168 | (1) |
|
Higher-Order Functions and Functional Programming |
|
|
169 | (1) |
|
Fixed-Size, Typed, and Shaped Arrays |
|
|
170 | (1) |
|
|
171 | (1) |
|
|
172 | (1) |
|
More Advanced Sorting Techniques |
|
|
173 | (3) |
|
|
176 | (1) |
|
|
177 | (1) |
|
|
178 | (5) |
|
|
183 | (20) |
|
|
183 | (3) |
|
Common Operations on Hashes |
|
|
186 | (1) |
|
Hash as a Collection of Counters |
|
|
187 | (1) |
|
|
188 | (1) |
|
|
189 | (1) |
|
|
190 | (2) |
|
|
192 | (1) |
|
|
193 | (2) |
|
|
195 | (2) |
|
Hashes as Dispatch Tables |
|
|
197 | (1) |
|
|
198 | (1) |
|
|
199 | (1) |
|
|
200 | (1) |
|
|
201 | (2) |
|
11 Case Study: Data Structure Selection |
|
|
203 | (34) |
|
The Ternary Conditional Operator |
|
|
203 | (1) |
|
The given...when "Switch" Statement |
|
|
204 | (2) |
|
Subroutine Named and Optional Parameters |
|
|
206 | (2) |
|
|
206 | (1) |
|
|
207 | (1) |
|
|
208 | (1) |
|
|
208 | (2) |
|
|
210 | (2) |
|
|
212 | (1) |
|
|
213 | (1) |
|
|
214 | (1) |
|
Constructing New Operators |
|
|
214 | (1) |
|
|
215 | (2) |
|
|
217 | (2) |
|
|
219 | (2) |
|
|
221 | (1) |
|
Building Your Own Data Structures |
|
|
222 | (5) |
|
|
223 | (1) |
|
|
224 | (1) |
|
|
224 | (3) |
|
|
227 | (2) |
|
|
229 | (1) |
|
Exercises: Huffman Coding |
|
|
230 | (7) |
|
|
230 | (1) |
|
|
231 | (1) |
|
Building the Huffman Code |
|
|
231 | (6) |
Part II. Moving Forward |
|
|
|
237 | (36) |
|
Objects, Methods, and Object-Oriented Programming |
|
|
237 | (2) |
|
|
239 | (1) |
|
|
240 | (2) |
|
|
242 | (3) |
|
Rectangles and Object Composition |
|
|
245 | (2) |
|
Instances as Return Values |
|
|
247 | (1) |
|
|
247 | (5) |
|
|
248 | (2) |
|
|
250 | (1) |
|
Multiple Inheritance: Attractive, but Is It Wise? |
|
|
251 | (1) |
|
|
252 | (4) |
|
Classes and Roles: An Example |
|
|
253 | (2) |
|
Role Composition and Code Reuse |
|
|
255 | (1) |
|
Roles, Classes, Objects, and Types |
|
|
256 | (1) |
|
|
256 | (2) |
|
|
258 | (1) |
|
|
259 | (5) |
|
|
260 | (1) |
|
Constructing Objects with Private Attributes |
|
|
261 | (3) |
|
Interface and Implementation |
|
|
264 | (1) |
|
Object-Oriented Programming: A Tale |
|
|
264 | (2) |
|
The Fable of the Shepherd |
|
|
265 | (1) |
|
|
265 | (1) |
|
|
266 | (4) |
|
|
266 | (1) |
|
|
267 | (1) |
|
Stepping Through the Code |
|
|
267 | (1) |
|
Stopping at the Right Place with Breakpoints |
|
|
268 | (1) |
|
Logging Information with Trace Points |
|
|
268 | (1) |
|
Stepping Through a Regex Match |
|
|
269 | (1) |
|
|
270 | (3) |
|
|
273 | (24) |
|
|
273 | (2) |
|
|
275 | (1) |
|
|
275 | (1) |
|
Named Rules (a.k.a. Subrules) |
|
|
276 | (3) |
|
|
279 | (2) |
|
|
281 | (1) |
|
|
282 | (2) |
|
A Grammar for Parsing JSON |
|
|
284 | (7) |
|
|
284 | (1) |
|
|
284 | (1) |
|
Writing the JSON Grammar Step by Step |
|
|
285 | (2) |
|
|
287 | (2) |
|
|
289 | (2) |
|
Inheritance and Mutable Grammars |
|
|
291 | (1) |
|
|
291 | (2) |
|
|
293 | (1) |
|
Exercise: A Grammar for an Arithmetic Calculator |
|
|
294 | (3) |
|
14 Functional Programming in Perl |
|
|
297 | (40) |
|
|
297 | (5) |
|
A Refresher on Functions as First-Class Objects |
|
|
297 | (2) |
|
Anonymous Subroutines and Lambdas |
|
|
299 | (1) |
|
|
300 | (2) |
|
List Processing and Pipeline Programming |
|
|
302 | (8) |
|
Feed and Backward Feed Operators |
|
|
303 | (1) |
|
The Reduction Metaoperator |
|
|
304 | (1) |
|
|
304 | (1) |
|
The Cross (X) and Zip (Z) Operators |
|
|
305 | (1) |
|
List Operators: A Summary |
|
|
306 | (1) |
|
|
307 | (3) |
|
Creating Your Own Map-Like Functions |
|
|
310 | (6) |
|
Custom versions of map, grep, etc. |
|
|
310 | (1) |
|
Our Own Version of a Sort Function |
|
|
311 | (2) |
|
An Iterator Version of map |
|
|
313 | (1) |
|
An Iterator Version of grep |
|
|
314 | (2) |
|
The gather and take Construct |
|
|
316 | (3) |
|
Lazy Lists and the Sequence Operator |
|
|
319 | (3) |
|
|
319 | (1) |
|
|
320 | (1) |
|
Using an Explicit Generator |
|
|
320 | (2) |
|
Currying and the Whatever Operator |
|
|
322 | (3) |
|
Creating a Curried Subroutine |
|
|
323 | (1) |
|
Currying an Existing Subroutine with the assuming Method |
|
|
323 | (1) |
|
Currying with the Whatever Star Parameter |
|
|
324 | (1) |
|
Using a Functional Programming Style |
|
|
325 | (4) |
|
|
325 | (1) |
|
A Nonfunctional Implementation of Merge Sort |
|
|
326 | (2) |
|
A Functional Implementation of Merge Sort |
|
|
328 | (1) |
|
|
329 | (4) |
|
|
333 | (1) |
|
|
334 | (3) |
|
|
337 | (8) |
|
Make It Clear, Keep It Simple |
|
|
337 | (1) |
|
|
338 | (2) |
|
|
340 | (3) |
|
|
343 | (2) |
A Solutions to the Exercises |
|
345 | (82) |
Index |
|
427 | |