about summary refs log tree commit diff stats
path: root/js/games/nluqo.github.io/~bh/ss-toc2.html
blob: b0b0917ea8f654aa7b5eb46960c5467a76949ed2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
<HTML>
<HEAD>
<TITLE>Simply Scheme: Introducing Computer Science</TITLE>
</HEAD>
<BODY>
<H1><EM>Simply Scheme: Introducing Computer Science</EM></H1>
<H3>2/e Copyright (C) 1999 MIT</H3>
<H1>Table of Contents</H1>

<TABLE width="100%"><TR><TD>
<IMG SRC="simply.jpg" ALT="cover photo">
<TD><TABLE>
<TR><TD align="right"><CITE><A HREF="http://www.cs.berkeley.edu/~bh/">Brian
Harvey</A><BR>University of California, Berkeley</CITE>
<TR><TD align="right"><CITE><A HREF="http://ccrma.stanford.edu/~matt">Matthew
Wright</A><BR>Stanford University</CITE>
<TR><TD align="right"><BR>
<TR><TD align="right"><A HREF="pdf/ssch00.pdf">Download PDF frontmatter</A>
<TR><TD align="right">[no back]
chapter thread <A HREF="ssch0/foreword.html"><STRONG>NEXT</STRONG></A>
<TR><TD align="right"><A HREF="http://mitpress.mit.edu/0262082810">MIT
Press web page for <CITE>Simply Scheme</CITE></A>
</TABLE></TABLE>

<HR>

<P>Below this short table of contents is an expanded table of contents
including sections within each chapter.  Click on the chapter name
to jump down.  You can also download the complete text of each chapter
in PDF format for elegant printing, or browse the HTML version.

Part introductions are included in the PDF of the following chapter.
Projects are included in the PDF of the preceding chapter.

<P><EM>Note:  This book is still in copyright, and in print.  It is
posted here for your personal use, not for resale or redistribution.
Thanks!</EM>

<UL>
<LI><A HREF="ss-toc2.html#foreword">Foreword</A> by
<A HREF="http://groups.csail.mit.edu/mac/users/hal/hal.html">Hal Abelson</A>
(<A HREF="pdf/ssch00.pdf">frontmatter in PDF</A>)
(<A HREF="ssch0/foreword.html">HTML</A>)
<LI><A HREF="ss-toc2.html#preface">Preface</A>
(<A HREF="ssch0/preface.html">HTML</A>)
<LI><A HREF="ss-toc2.html#instructor">To the Instructor</A>
(<A HREF="ssch0/instructor.html">HTML</A>)
<LI><A HREF="ss-toc2.html#ack">Acknowledgements</A>
(<A HREF="ssch0/ack.html">HTML</A>)
<LI>I. <A HREF="ss-toc2.html#part1">Introduction: Functions</A>
(<A HREF="ssch1/part1.html">HTML</A>)
<UL>
<LI>1. <A HREF="ss-toc2.html#showing">Showing Off Scheme</A>
(<A HREF="pdf/ssch01.pdf">PDF</A>)
(<A HREF="ssch1/showing.html">HTML</A>)
<LI>2. <A HREF="ss-toc2.html#functions">Functions</A>
(<A HREF="pdf/ssch02.pdf">PDF</A>)
(<A HREF="ssch2/functions.html">HTML</A>)
</UL>
<LI>II. <A HREF="ss-toc2.html#part2">Composition of Functions</A>
(<A HREF="ssch3/part2.html">HTML</A>)
<UL>
<LI>3. <A HREF="ss-toc2.html#people">Expressions</A>
(<A HREF="pdf/ssch03.pdf">PDF</A>)
(<A HREF="ssch3/people.html">HTML</A>)
<LI>4. <A HREF="ss-toc2.html#defining">Defining Your Own Procedures</A>
(<A HREF="pdf/ssch04.pdf">PDF</A>)
(<A HREF="ssch4/defining.html">HTML</A>)
<LI>5. <A HREF="ss-toc2.html#words">Words and Sentences</A>
(<A HREF="pdf/ssch05.pdf">PDF</A>)
(<A HREF="ssch5/words.html">HTML</A>)
<LI>6. <A HREF="ss-toc2.html#true">True and False</A>
(<A HREF="pdf/ssch06.pdf">PDF</A>)
(<A HREF="ssch6/true.html">HTML</A>)
<LI>7. <A HREF="ss-toc2.html#variables">Variables</A>
(<A HREF="pdf/ssch07.pdf">PDF</A>)
(<A HREF="ssch7/variables.html">HTML</A>)
</UL>
<LI>III. <A HREF="ss-toc2.html#part3">Functions as Data</A>
(<A HREF="ssch8/part3.html">HTML</A>)
<UL>
<LI>8. <A HREF="ss-toc2.html#higher">Higher-Order Functions</A>
(<A HREF="pdf/ssch08.pdf">PDF</A>)
(<A HREF="ssch8/higher.html">HTML</A>)
<LI>9. <A HREF="ss-toc2.html#lambda">Lambda</A>
(<A HREF="pdf/ssch09.pdf">PDF</A>)
(<A HREF="ssch9/lambda.html">HTML</A>)
<LI><A HREF="ss-toc2.html#bridge">Project: Scoring Bridge Hands</A>
(<A HREF="ssch9/bridge.html">HTML</A>)
<LI>10. <A HREF="ss-toc2.html#ttt">Example: Tic-Tac-Toe</A>
(<A HREF="pdf/ssch10.pdf">PDF</A>)
(<A HREF="ssch10/ttt.html">HTML</A>)
</UL>
<LI>IV. <A HREF="ss-toc2.html#part4">Recursion</A>
(<A HREF="ssch11/part4.html">HTML</A>)
<UL>
<LI>11. <A HREF="ss-toc2.html#recursion">Introduction to Recursion</A>
(<A HREF="pdf/ssch11.pdf">PDF</A>)
(<A HREF="ssch11/recursion.html">HTML</A>)
<LI>12. <A HREF="ss-toc2.html#leap">The Leap of Faith</A>
(<A HREF="pdf/ssch12.pdf">PDF</A>)
(<A HREF="ssch12/leap.html">HTML</A>)
<LI>13. <A HREF="ss-toc2.html#convince-recur">How Recursion Works</A>
(<A HREF="pdf/ssch13.pdf">PDF</A>)
(<A HREF="ssch13/convince-recur.html">HTML</A>)
<LI>14. <A HREF="ss-toc2.html#recur-patterns">Common Patterns in Recursive Procedures</A>
(<A HREF="pdf/ssch14.pdf">PDF</A>)
(<A HREF="ssch14/recur-patterns.html">HTML</A>)
<LI><A HREF="ss-toc2.html#number-name">Project: Spelling Names of Huge Numbers</A>
(<A HREF="ssch14/number-name.html">HTML</A>)
<LI>15. <A HREF="ss-toc2.html#adv-recur">Advanced Recursion</A>
(<A HREF="pdf/ssch15.pdf">PDF</A>)
(<A HREF="ssch15/adv-recur.html">HTML</A>)
<LI><A HREF="ss-toc2.html#poker">Project: Scoring Poker Hands</A>
(<A HREF="ssch15/poker.html">HTML</A>)
<LI>16. <A HREF="ss-toc2.html#match">Example: Pattern Matcher</A>
(<A HREF="pdf/ssch16.pdf">PDF</A>)
(<A HREF="ssch16/match.html">HTML</A>)
</UL>
<LI>V. <A HREF="ss-toc2.html#part5">Abstraction</A>
(<A HREF="ssch17/part5.html">HTML</A>)
<UL>
<LI>17. <A HREF="ss-toc2.html#lists">Lists</A>
(<A HREF="pdf/ssch17.pdf">PDF</A>)
(<A HREF="ssch17/lists.html">HTML</A>)
<LI>18. <A HREF="ss-toc2.html#trees">Trees</A>
(<A HREF="pdf/ssch18.pdf">PDF</A>)
(<A HREF="ssch18/trees.html">HTML</A>)
<LI>19. <A HREF="ss-toc2.html#implement-hof">Implementing Higher-Order Functions</A>
(<A HREF="pdf/ssch19.pdf">PDF</A>)
(<A HREF="ssch19/implement-hof.html">HTML</A>)
</UL>
<LI>VI. <A HREF="ss-toc2.html#part6">Sequential Programming</A>
(<A HREF="ssch20/part6.html">HTML</A>)
<UL>
<LI>20. <A HREF="ss-toc2.html#io">Input and Output</A>
(<A HREF="pdf/ssch20.pdf">PDF</A>)
(<A HREF="ssch20/io.html">HTML</A>)
<LI>21. <A HREF="ss-toc2.html#functions-implement">Example: The <CODE>Functions</CODE> Program</A>
(<A HREF="pdf/ssch21.pdf">PDF</A>)
(<A HREF="ssch21/functions-implement.html">HTML</A>)
<LI>22. <A HREF="ss-toc2.html#files">Files</A>
(<A HREF="pdf/ssch22.pdf">PDF</A>)
(<A HREF="ssch22/files.html">HTML</A>)
<LI>23. <A HREF="ss-toc2.html#vectors">Vectors</A>
(<A HREF="pdf/ssch23.pdf">PDF</A>)
(<A HREF="ssch23/vectors.html">HTML</A>)
<LI>24. <A HREF="ss-toc2.html#spread">Example: A Spreadsheet Program</A>
(<A HREF="pdf/ssch24.pdf">PDF</A>)
(<A HREF="ssch24/spread.html">HTML</A>)
<LI>25. <A HREF="ss-toc2.html#spread-implement">Implementing the Spreadsheet Program</A>
(<A HREF="pdf/ssch25.pdf">PDF</A>)
(<A HREF="ssch25/spread-implement.html">HTML</A>)
<LI><A HREF="ss-toc2.html#database">Project: A Database Program</A>
(<A HREF="ssch25/database.html">HTML</A>)
</UL>
<LI>VII. <A HREF="ss-toc2.html#part7">Conclusion: Computer Science</A>
(<A HREF="ssch26/part7.html">HTML</A>)
<UL>
<LI>26. <A HREF="ss-toc2.html#preview">What's Next?</A>
(<A HREF="pdf/ssch26.pdf">PDF</A>)
(<A HREF="ssch26/preview.html">HTML</A>)
</UL>
<LI>Appendices
<UL>
<LI>A. <A HREF="ss-toc2.html#appendix-running">Running Scheme</A>
(<A HREF="pdf/ssch27.pdf">backmatter in PDF</A>)
(<A HREF="ssch27/appendix-running.html">HTML</A>)
<LI>B. <A HREF="ss-toc2.html#appendix-cl">Common Lisp</A>
(<A HREF="ssch27/appendix-cl.html">HTML</A>)
<LI>C. <A HREF="ss-toc2.html#appendix-simply">Scheme Initialization File</A>
(<A HREF="ssch27/appendix-simply.html">HTML</A>)
<LI>D. <A HREF="ss-toc2.html#appendix-gpl">GNU General Public License</A>
(<A HREF="ssch27/appendix-gpl.html">HTML</A>)
</UL>
<LI><A HREF="ss-toc2.html#credits">Credits</A>
(<A HREF="ssch27/credits.html">HTML</A>)
<LI><A HREF="ss-toc2.html#appendix-funlist">Alphabetical Table of Scheme Primitives</A>
(<A HREF="ssch27/appendix-funlist.html">HTML</A>)
<LI><A HREF="ss-toc2.html#glossary">Glossary</A>
(<A HREF="ssch27/glossary.html">HTML</A>)
<LI><A HREF="ss-toc2.html#appuindex">Index of Defined Procedures</A>
(<A HREF="ssch27/appuindex.html">HTML</A>)
<LI><A HREF="ss-toc2.html#appindex">General Index</A>
(<A HREF="ssch27/appindex.html">HTML</A>)
<LI><A HREF="ss-toc2.html#category">Table of Scheme Primitives by Category</A>
(<A HREF="ssch27/category.html">HTML</A>)
</UL>
<P><BR>
<HR>
<P><BR>

<TABLE><TR><TD><H3><A name="foreword">Foreword</A> by
<A HREF="http://groups.csail.mit.edu/mac/users/hal/hal.html">Hal Abelson</A>
</H3><TD>
(<A HREF="pdf/ssch00.pdf">frontmatter in PDF</A>)
(<A HREF="ssch0/foreword.html">HTML</A>)
</TABLE>
<TABLE><TR><TD><H3><A name="preface">Preface</A></H3><TD>
(<A HREF="ssch0/preface.html">HTML</A>)
</TABLE>
<UL>
<LI>One Big Idea: Symbolic Programming
<LI>Lisp and Radical Computer Science
<LI>Who Should Read This Book
<LI>How to Read This Book
</UL>
<TABLE><TR><TD><H3><A name="instructor">To the Instructor</A></H3><TD>
(<A HREF="ssch0/instructor.html">HTML</A>)
</TABLE>
<UL>
<LI>Lists and Sentences
<LI>Sentences and Words
<LI>Overloading in the Text Abstraction
<LI>Higher-Order Procedures, Lambda, and Recursion
<LI>Mutators and Environments
</UL>
<TABLE><TR><TD><H3><A name="ack">Acknowledgements</A></H3><TD>
(<A HREF="ssch0/ack.html">HTML</A>)
</TABLE>
<TABLE><TR><TD><H2>I. <A name="part1">Introduction: Functions</A></H2><TD>
(<A HREF="ssch1/part1.html">HTML</A>)
</TABLE>
<TABLE><TR><TD><H3>1. <A name="showing">Showing Off Scheme</A></H3><TD>
(<A HREF="pdf/ssch01.pdf">PDF</A>)
(<A HREF="ssch1/showing.html">HTML</A>)
</TABLE>
<UL>
<LI>Talking to Scheme
<LI>Recovering from Typing Errors
<LI>Exiting Scheme
<LI>More Examples
<LI>Example: Acronyms
<LI>Example: Pig Latin
<LI>Example: Ice Cream Choices
<LI>Example: Combinations from a Set
<LI>Example: Factorial
<LI>Play with the Procedures
</UL>
<TABLE><TR><TD><H3>2. <A name="functions">Functions</A></H3><TD>
(<A HREF="pdf/ssch02.pdf">PDF</A>)
(<A HREF="ssch2/functions.html">HTML</A>)
</TABLE>
<UL>
<LI>Arithmetic
<LI>Words
<LI>Domain and Range
<LI>More Types: Sentences and Booleans
<LI>Our Favorite Type: Functions
<LI>Play with It
<LI>Thinking about What You've Done
</UL>
<TABLE><TR><TD><H2>II. <A name="part2">Composition of Functions</A></H2><TD>
(<A HREF="ssch3/part2.html">HTML</A>)

</TABLE>
<TABLE><TR><TD><H3>3. <A name="people">Expressions</A></H3><TD>
(<A HREF="pdf/ssch03.pdf">PDF</A>)
(<A HREF="ssch3/people.html">HTML</A>)
</TABLE>
<UL>
<LI>Little People
<LI>Result Replacement
<LI>Plumbing Diagrams
<LI>Pitfalls
</UL>
<TABLE><TR><TD><H3>4. <A name="defining">Defining Your Own Procedures</A></H3><TD>
(<A HREF="pdf/ssch04.pdf">PDF</A>)
(<A HREF="ssch4/defining.html">HTML</A>)
</TABLE>
<UL>
<LI>How to Define a Procedure
<LI>Special Forms
<LI>Functions and Procedures
<LI>Argument Names versus Argument Values
<LI>Procedure as Generalization
<LI>Composability
<LI>The Substitution Model
<LI>Pitfalls
</UL>
<TABLE><TR><TD><H3>5. <A name="words">Words and Sentences</A></H3><TD>
(<A HREF="pdf/ssch05.pdf">PDF</A>)
(<A HREF="ssch5/words.html">HTML</A>)
</TABLE>
<UL>
<LI>Selectors
<LI>Constructors
<LI>First-Class Words and Sentences
<LI>Pitfalls
</UL>
<TABLE><TR><TD><H3>6. <A name="true">True and False</A></H3><TD>
(<A HREF="pdf/ssch06.pdf">PDF</A>)
(<A HREF="ssch6/true.html">HTML</A>)
</TABLE>
<UL>
<LI>Predicates
<LI>Using Predicates
<LI><CODE>If</CODE> Is a Special Form
<LI>So Are <CODE>And</CODE> and <CODE>Or</CODE>
<LI>Everything That Isn't False Is True
<LI>Decisions, Decisions, Decisions
<LI><CODE>If</CODE> Is Composable
<LI>Pitfalls
</UL>
<TABLE><TR><TD><H3>7. <A name="variables">Variables</A></H3><TD>
(<A HREF="pdf/ssch07.pdf">PDF</A>)
(<A HREF="ssch7/variables.html">HTML</A>)
</TABLE>
<UL>
<LI>How Little People Do Variables
<LI>Global and Local Variables
<LI>The Truth about Substitution
<LI><CODE>Let</CODE>
<LI>Pitfalls
</UL>
<TABLE><TR><TD><H2>III. <A name="part3">Functions as Data</A></H2><TD>
(<A HREF="ssch8/part3.html">HTML</A>)
</TABLE>
<TABLE><TR><TD><H3>8. <A name="higher">Higher-Order Functions</A></H3><TD>
(<A HREF="pdf/ssch08.pdf">PDF</A>)
(<A HREF="ssch8/higher.html">HTML</A>)
</TABLE>
<UL>
<LI><CODE>Every</CODE>
<LI>A Pause for Reflection
<LI><CODE>Keep</CODE>
<LI><CODE>Accumulate</CODE>
<LI>Combining Higher-Order Functions
<LI>Choosing the Right Tool
<LI>First-Class Functions and First-Class Sentences
<LI><CODE>Repeated</CODE>
<LI>Pitfalls
</UL>
<TABLE><TR><TD><H3>9. <A name="lambda">Lambda</A></H3><TD>
(<A HREF="pdf/ssch09.pdf">PDF</A>)
(<A HREF="ssch9/lambda.html">HTML</A>)
</TABLE>
<UL>
<LI>Procedures That Return Procedures
<LI>The Truth about <CODE>Define</CODE>
<LI>The Truth about <CODE>Let</CODE>
<LI>Name Conflicts
<LI>Named and Unnamed Functions
<LI>Pitfalls
</UL>
<TABLE><TR><TD><H3><A name="bridge">Project: Scoring Bridge Hands</A></H3><TD>
(<A HREF="ssch9/bridge.html">HTML</A>)
</TABLE>
<TABLE><TR><TD><H3>10. <A name="ttt">Example: Tic-Tac-Toe</A></H3><TD>
(<A HREF="pdf/ssch10.pdf">PDF</A>)
(<A HREF="ssch10/ttt.html">HTML</A>)
</TABLE>
<UL>
<LI>A Warning
<LI>Technical Terms in Tic-Tac-Toe
<LI>Thinking about the Program Structure
<LI>The First Step: Triples
<LI>Finding the Triples
<LI>Using <CODE>Every</CODE> with Two-Argument Procedures
<LI>Can the Computer Win on This Move?
<LI>If So, in Which Square?
<LI>Second Verse, Same as the First
<LI>Now the Strategy Gets Complicated
<LI>Finding the Pivots
<LI>Taking the Offensive
<LI>Leftovers
<LI>Complete Program Listing
</UL>
<TABLE><TR><TD><H2>IV. <A name="part4">Recursion</A></H2><TD>
(<A HREF="ssch11/part4.html">HTML</A>)
</TABLE>
<TABLE><TR><TD><H3>11. <A name="recursion">Introduction to Recursion</A></H3><TD>
(<A HREF="pdf/ssch11.pdf">PDF</A>)
(<A HREF="ssch11/recursion.html">HTML</A>)
</TABLE>
<UL>
<LI>A Separate Procedure for Each Length
<LI>Use What You Have to Get What You Need
<LI>Notice That They're All the Same
<LI>Notice That They're Almost All the Same
<LI>Base Cases and Recursive Calls
<LI>Pig Latin
<LI>Problems for You to Try
<LI>Our Solutions
<LI>Pitfalls
</UL>
<TABLE><TR><TD><H3>12. <A name="leap">The Leap of Faith</A></H3><TD>
(<A HREF="pdf/ssch12.pdf">PDF</A>)
(<A HREF="ssch12/leap.html">HTML</A>)
</TABLE>
<UL>
<LI>From the Combining Method to the Leap of Faith
<LI>Example: <CODE>Reverse</CODE>
<LI>The Leap of Faith
<LI>The Base Case
<LI>Example: <CODE>Factorial</CODE>
<LI>Likely Guesses for Smaller Subproblems
<LI>Example: <CODE>Downup</CODE>
<LI>Example: <CODE>Evens</CODE>
<LI>Simplifying Base Cases
<LI>Pitfalls
</UL>
<TABLE><TR><TD><H3>13. <A name="convince-recur">How Recursion Works</A></H3><TD>
(<A HREF="pdf/ssch13.pdf">PDF</A>)
(<A HREF="ssch13/convince-recur.html">HTML</A>)
</TABLE>
<UL>
<LI>Little People and Recursion
<LI>Tracing
<LI>Pitfalls
</UL>
<TABLE><TR><TD><H3>14. <A name="recur-patterns">Common Patterns in Recursive Procedures</A></H3><TD>
(<A HREF="pdf/ssch14.pdf">PDF</A>)
(<A HREF="ssch14/recur-patterns.html">HTML</A>)
</TABLE>
<UL>
<LI>The <CODE>Every</CODE> Pattern
<LI>The <CODE>Keep</CODE> Pattern
<LI>The <CODE>Accumulate</CODE> Pattern
<LI>Combining Patterns
<LI>Helper Procedures
<LI>How to Use Recursive Patterns
<LI>Problems That Don't Follow Patterns
<LI>Pitfalls
</UL>
<TABLE><TR><TD><H3><A name="number-name">Project: Spelling Names of Huge Numbers</A></H3><TD>
(<A HREF="ssch14/number-name.html">HTML</A>)
</TABLE>
<TABLE><TR><TD><H3>15. <A name="adv-recur">Advanced Recursion</A></H3><TD>
(<A HREF="pdf/ssch15.pdf">PDF</A>)
(<A HREF="ssch15/adv-recur.html">HTML</A>)
</TABLE>
<UL>
<LI>Example: <CODE>Sort</CODE>
<LI>Example: <CODE>From-Binary</CODE>
<LI>Example: <CODE>Mergesort</CODE>
<LI>Example: <CODE>Subsets</CODE>
<LI>Pitfalls
</UL>
<TABLE><TR><TD><H3><A name="poker">Project: Scoring Poker Hands</A></H3><TD>
(<A HREF="ssch15/poker.html">HTML</A>)
</TABLE>
<UL>
<LI>Extra Work for Hotshots
</UL>
<TABLE><TR><TD><H3>16. <A name="match">Example: Pattern Matcher</A></H3><TD>
(<A HREF="pdf/ssch16.pdf">PDF</A>)
(<A HREF="ssch16/match.html">HTML</A>)
</TABLE>
<UL>
<LI>Problem Description
<LI>Implementation: When Are Two Sentences Equal?
<LI>When Are Two Sentences Nearly Equal?
<LI>Matching with Alternatives
<LI>Backtracking
<LI>Matching Several Words
<LI>Combining the Placeholders
<LI>Naming the Matched Text
<LI>The Final Version
<LI>Abstract Data Types
<LI>Backtracking and <CODE>Known-Values</CODE>
<LI>How We Wrote It
<LI>Complete Program Listing
</UL>
<TABLE><TR><TD><H2>V. <A name="part5">Abstraction</A></H2><TD>
(<A HREF="ssch17/part5.html">HTML</A>)
</TABLE>
<TABLE><TR><TD><H3>17. <A name="lists">Lists</A></H3><TD>
(<A HREF="pdf/ssch17.pdf">PDF</A>)
(<A HREF="ssch17/lists.html">HTML</A>)
</TABLE>
<UL>
<LI>Selectors and Constructors
<LI>Programming with Lists
<LI>The Truth about Sentences
<LI>Higher-Order Functions
<LI>Other Primitives for Lists
<LI>Association Lists
<LI>Functions That Take Variable Numbers of Arguments
<LI>Recursion on Arbitrary Structured Lists
<LI>Pitfalls
</UL>
<TABLE><TR><TD><H3>18. <A name="trees">Trees</A></H3><TD>
(<A HREF="pdf/ssch18.pdf">PDF</A>)
(<A HREF="ssch18/trees.html">HTML</A>)
</TABLE>
<UL>
<LI>Example: The World
<LI>How Big Is My Tree?
<LI>Mutual Recursion
<LI>Searching for a Datum in the Tree
<LI>Locating a Datum in the Tree
<LI>Representing Trees as Lists
<LI>Abstract Data Types
<LI>An Advanced Example: Parsing Arithmetic Expressions
<LI>Pitfalls
</UL>
<TABLE><TR><TD><H3>19. <A name="implement-hof">Implementing Higher-Order Functions</A></H3><TD>
(<A HREF="pdf/ssch19.pdf">PDF</A>)
(<A HREF="ssch19/implement-hof.html">HTML</A>)
</TABLE>
<UL>
<LI>Generalizing Patterns
<LI>The <CODE>Every</CODE> Pattern Revisited
<LI>The Difference between <CODE>Map</CODE> and <CODE>Every</CODE>
<LI><CODE>Filter</CODE>
<LI><CODE>Accumulate</CODE> and <CODE>Reduce</CODE>
<LI>Robustness
<LI>Higher-Order Functions for Structured Lists
<LI>The Zero-Trip Do Loop
<LI>Pitfalls
</UL>
<TABLE><TR><TD><H2>VI. <A name="part6">Sequential Programming</A></H2><TD>
(<A HREF="ssch20/part6.html">HTML</A>)
</TABLE>
<TABLE><TR><TD><H3>20. <A name="io">Input and Output</A></H3><TD>
(<A HREF="pdf/ssch20.pdf">PDF</A>)
(<A HREF="ssch20/io.html">HTML</A>)
</TABLE>
<UL>
<LI>Printing
<LI>Side Effects and Sequencing
<LI>The <CODE>Begin</CODE> Special Form
<LI>This Isn't Functional Programming
<LI>Not Moving to the Next Line
<LI>Strings
<LI>A Higher-Order Procedure for Sequencing
<LI>Tic-Tac-Toe Revisited
<LI>Accepting User Input
<LI>Aesthetic Board Display
<LI>Reading and Writing Normal Text
<LI>Formatted Text
<LI>Sequential Programming and Order of Evaluation
<LI>Pitfalls
</UL>
<TABLE><TR><TD><H3>21. <A name="functions-implement">Example: The <CODE>Functions</CODE> Program</A></H3><TD>
(<A HREF="pdf/ssch21.pdf">PDF</A>)
(<A HREF="ssch21/functions-implement.html">HTML</A>)
</TABLE>
<UL>
<LI>The Main Loop
<LI>The Difference between a Procedure and Its Name
<LI>The Association List of Functions
<LI>Domain Checking
<LI>Intentionally Confusing a Function with Its Name
<LI>More on Higher-Order Functions
<LI>More Robustness
<LI>Complete Program Listing
</UL>
<TABLE><TR><TD><H3>22. <A name="files">Files</A></H3><TD>
(<A HREF="pdf/ssch22.pdf">PDF</A>)
(<A HREF="ssch22/files.html">HTML</A>)
</TABLE>
<UL>
<LI>Ports
<LI>Writing Files for People to Read
<LI>Using a File as a Database
<LI>Transforming the Lines of a File
<LI>Justifying Text
<LI>Preserving Spacing of Text from Files
<LI>Merging Two Files
<LI>Writing Files for Scheme to Read
<LI>Pitfalls
</UL>
<TABLE><TR><TD><H3>23. <A name="vectors">Vectors</A></H3><TD>
(<A HREF="pdf/ssch23.pdf">PDF</A>)
(<A HREF="ssch23/vectors.html">HTML</A>)
</TABLE>
<UL>
<LI>The Indy 500
<LI>Vectors
<LI>Using Vectors in Programs
<LI>Non-Functional Procedures and State
<LI>Shuffling a Deck
<LI>More Vector Tools
<LI>The Vector Pattern of Recursion
<LI>Vectors versus Lists
<LI>State, Sequence, and Effects
<LI>Pitfalls
</UL>
<TABLE><TR><TD><H3>24. <A name="spread">Example: A Spreadsheet Program</A></H3><TD>
(<A HREF="pdf/ssch24.pdf">PDF</A>)
(<A HREF="ssch24/spread.html">HTML</A>)
</TABLE>
<UL>
<LI>Limitations of Our Spreadsheet
<LI>Spreadsheet Commands
<LI>Moving the Selection
<LI>Putting Values in Cells
<LI>Formulas
<LI>Displaying Formula Values
<LI>Loading Spreadsheet Commands from a File
<LI>Application Programs and Abstraction
</UL>
<TABLE><TR><TD><H3>25. <A name="spread-implement">Implementing the Spreadsheet Program</A></H3><TD>
(<A HREF="pdf/ssch25.pdf">PDF</A>)
(<A HREF="ssch25/spread-implement.html">HTML</A>)
</TABLE>
<UL>
<LI>Cells, Cell Names, and Cell IDs
<LI>The Command Processor
<LI>Cell Selection Commands
<LI>The <CODE>Load</CODE> Command
<LI>The <CODE>Put</CODE> Command
<LI>The Formula Translator
<LI>The Dependency Manager
<LI>The Expression Evaluator
<LI>The Screen Printer
<LI>The Cell Manager
<LI>Complete Program Listing
</UL>
<TABLE><TR><TD><H3><A name="database">Project: A Database Program</A></H3><TD>
(<A HREF="ssch25/database.html">HTML</A>)

</TABLE>
<UL>
<LI>A Sample Session with Our Database
<LI>How Databases Are Stored Internally
<LI>The Current Database
<LI>Implementing the Database Program Commands
<LI>Additions to the Program
<LI>Extra Work for Hotshots
</UL>
<TABLE><TR><TD><H2>VII. <A name="part7">Conclusion: Computer Science</A></H2><TD>
(<A HREF="ssch26/part7.html">HTML</A>)
</TABLE>
<TABLE><TR><TD><H3>26. <A name="preview">What's Next?</A></H3><TD>
(<A HREF="pdf/ssch26.pdf">PDF</A>)
(<A HREF="ssch26/preview.html">HTML</A>)
</TABLE>
<UL>
<LI>The Best Computer Science Book
<LI>Beyond <EM>SICP</EM>
<LI>Standard Scheme
<LI>Last Words
</UL>
<H2>Appendices</H2>
</TABLE>
<TABLE><TR><TD><H3>A. <A name="appendix-running">Running Scheme</A></H3><TD>
(<A HREF="pdf/ssch27.pdf">backmatter in PDF</A>)
(<A HREF="ssch27/appendix-running.html">HTML</A>)
</TABLE>
<UL>
<LI>The Program Development Cycle
<LI>Integrated Editing
<LI>Getting Our Programs
<LI>Tuning Our Programs for Your System
<LI>Loading Our Programs
<LI>Versions of Scheme
<LI>Scheme Standards
</UL>
<TABLE><TR><TD><H3>B. <A name="appendix-cl">Common Lisp</A></H3><TD>
(<A HREF="ssch27/appendix-cl.html">HTML</A>)
</TABLE>
<UL>
<LI>Why Common Lisp Exists
<LI>Defining Procedures and Variables
<LI>The Naming Convention for Predicates
<LI>No Words or Sentences
<LI>True and False
<LI>Files
<LI>Arrays
<LI>Equivalents to Scheme Primitives
<LI>A Separate Name Space for Procedures
<LI><CODE>Lambda</CODE>
<LI>More about <CODE>Function</CODE>
<LI>Writing Higher-Order Procedures
</UL>
<TABLE><TR><TD><H3>C. <A name="appendix-simply">Scheme Initialization File</A></H3><TD>
(<A HREF="ssch27/appendix-simply.html">HTML</A>)
</TABLE>
<TABLE><TR><TD><H3>D. <A name="appendix-gpl">GNU General Public License</A></H3><TD>
(<A HREF="ssch27/appendix-gpl.html">HTML</A>)

</TABLE>
<TABLE><TR><TD><H3><A name="credits">Credits</A></H3><TD>
(<A HREF="ssch27/credits.html">HTML</A>)
</TABLE>
<TABLE><TR><TD><H3><A name="appendix-funlist">Alphabetical Table of Scheme Primitives</A></H3><TD>
(<A HREF="ssch27/appendix-funlist.html">HTML</A>)
</TABLE>
<TABLE><TR><TD><H3><A name="glossary">Glossary</A></H3><TD>
(<A HREF="ssch27/glossary.html">HTML</A>)
</TABLE>
<TABLE><TR><TD><H3><A name="appuindex">Index of Defined Procedures</A></H3><TD>
(<A HREF="ssch27/appuindex.html">HTML</A>)
</TABLE>
<TABLE><TR><TD><H3><A name="appindex">General Index</A></H3><TD>
(<A HREF="ssch27/appindex.html">HTML</A>)
</TABLE>
<TABLE><TR><TD><H3><A name="category">Table of Scheme Primitives by Category</A></H3><TD>
(<A HREF="ssch27/category.html">HTML</A>)
</TABLE>

<P><BR>
<HR>
<P><BR>
<P>
[no back]
chapter thread <A HREF="ssch0/foreword.html"><STRONG>NEXT</STRONG></A>

<P>
<ADDRESS>
<A HREF="index.html">Brian Harvey</A>, 
<CODE>bh@cs.berkeley.edu</CODE>
</ADDRESS>
</BODY>
</HTML>
span> increment i loop +next-character } i <- add i, 1 print screen, c, color column <- add column, 1 loop } was-at-left?:bool <- equal column, left clear-line-until screen, right { break-if was-at-left? row <- add row, 1 } move-cursor screen, row, left ] scenario render-text-wraps-barely-long-lines [ local-scope assume-screen 5/width, 5/height run [ render-text screen, [abcde], 0/left, 4/right, 7/white, 1/row ] screen-should-contain [ . . .abcd. .e . . . ] ] # assumes programming environment has no sandboxes; restores them from previous session def restore-sandboxes env:&:environment, resources:&:resources -> env:&:environment [ local-scope load-inputs # read all scenarios, pushing them to end of a list of scenarios idx:num <- copy 0 curr:&:sandbox <- copy null prev:&:sandbox <- copy null { filename:text <- append [lesson/], idx contents:text <- slurp resources, filename break-unless contents # stop at first error; assuming file didn't exist # todo: handle empty sandbox # create new sandbox for file curr <- new sandbox:type *curr <- put *curr, data:offset, contents <end-restore-sandbox> { break-if idx *env <- put *env, sandbox:offset, curr } { break-unless idx *prev <- put *prev, next-sandbox:offset, curr } idx <- add idx, 1 prev <- copy curr loop } # update sandbox count *env <- put *env, number-of-sandboxes:offset, idx ] # print the fake sandbox screen to 'screen' with appropriate delimiters # leave cursor at start of next line def render-screen screen:&:screen, sandbox-screen:&:screen, left:num, right:num, row:num -> row:num, screen:&:screen [ local-scope load-inputs return-unless sandbox-screen # print 'screen:' row <- render-text screen, [screen:], left, right, 245/grey, row screen <- move-cursor screen, row, left # start printing sandbox-screen column:num <- copy left s-width:num <- screen-width sandbox-screen s-height:num <- screen-height sandbox-screen buf:&:@:screen-cell <- get *sandbox-screen, data:offset stop-printing:num <- add left, s-width, 3 max-column:num <- min stop-printing, right i:num <- copy 0 len:num <- length *buf screen-height:num <- screen-height screen { done?:bool <- greater-or-equal i, len break-if done? done? <- greater-or-equal row, screen-height break-if done? column <- copy left screen <- move-cursor screen, row, column # initial leader for each row: two spaces and a '.' space:char <- copy 32/space print screen, space, 245/grey print screen, space, 245/grey full-stop:char <- copy 46/period print screen, full-stop, 245/grey column <- add left, 3 { # print row row-done?:bool <- greater-or-equal column, max-column break-if row-done? curr:screen-cell <- index *buf, i c:char <- get curr, contents:offset color:num <- get curr, color:offset { # damp whites down to grey white?:bool <- equal color, 7/white break-unless white? color <- copy 245/grey } print screen, c, color column <- add column, 1 i <- add i, 1 loop } # print final '.' print screen, full-stop, 245/grey column <- add column, 1 { # clear rest of current line line-done?:bool <- greater-than column, right break-if line-done? print screen, space column <- add column, 1 loop } row <- add row, 1 loop } ] scenario run-updates-results [ local-scope trace-until 100/app # trace too long assume-screen 50/width, 12/height # define a recipe (no indent for the 'add' line below so column numbers are more obvious) assume-resources [ [lesson/recipes.mu] <- [ || |recipe foo [| | local-scope| | z:num <- add 2, 2| | reply z| |]| ] ] # sandbox editor contains an instruction without storing outputs env:&:environment <- new-programming-environment resources, screen, [foo] # contents of sandbox editor render-all screen, env, render $clear-trace # run the code in the editors assume-console [ press F4 ] event-loop screen, console, env, resources screen-should-contain [ . run (F4) . . . .──────────────────────────────────────────────────. .0 edit copy delete . .foo . .4 . .──────────────────────────────────────────────────. . . ] # the new sandbox should be saved to disk trace-should-contain [ app: save sandboxes ] # make a change (incrementing one of the args to 'add'), then rerun assume-resources [ [lesson/recipes.mu] <- [ || |recipe foo [| | local-scope| | z:num <- add 2, 3| | reply z| |]| ] ] $clear-trace assume-console [ press F4 ] run [ event-loop screen, console, env, resources ] # check that screen updates the result on the right screen-should-contain [ . run (F4) . . . .──────────────────────────────────────────────────. .0 edit copy delete . .foo . .5 . .──────────────────────────────────────────────────. . . ] # no need to save sandboxes all over again trace-should-not-contain [ app: save sandboxes ] ] scenario run-instruction-manages-screen-per-sandbox [ local-scope trace-until 100/app # trace too long assume-screen 50/width, 20/height # empty recipes assume-resources [ ] # sandbox editor contains an instruction env:&:environment <- new-programming-environment resources, screen, [print screen, 4] # contents of sandbox editor render-all screen, env, render # run the code in the editor assume-console [ press F4 ] run [ event-loop screen, console, env, resources ] # check that it prints a little toy screen screen-should-contain [ . run (F4) . . . .──────────────────────────────────────────────────. .0 edit copy delete . .print screen, 4 . .screen: . . .4 . . . . . . . . . . . . . . . . . . .──────────────────────────────────────────────────. . . ] ] def editor-contents editor:&:editor -> result:text [ local-scope load-inputs buf:&:buffer:char <- new-buffer 80 curr:&:duplex-list:char <- get *editor, data:offset # skip § sentinel assert curr, [editor without data is illegal; must have at least a sentinel] curr <- next curr return-unless curr, null { break-unless curr c:char <- get *curr, value:offset buf <- append buf, c curr <- next curr loop } result <- buffer-to-array buf ] scenario editor-provides-edited-contents [ local-scope assume-screen 10/width, 5/height e:&:editor <- new-editor [abc], 0/left, 10/right assume-console [ left-click 1, 2 type [def] ] run [ editor-event-loop screen, console, e s:text <- editor-contents e 1:@:char/raw <- copy *s ] memory-should-contain [ 1:array:character <- [abdefc] ] ] # scrolling through sandboxes scenario scrolling-down-past-bottom-of-sandbox-editor [ local-scope trace-until 100/app # trace too long assume-screen 50/width, 20/height # initialize assume-resources [ ] env:&:environment <- new-programming-environment resources, screen, [add 2, 2] render-all screen, env, render assume-console [ # create a sandbox press F4 ] event-loop screen, console, env, resources screen-should-contain [ . run (F4) . . . .──────────────────────────────────────────────────. .0 edit copy delete . .add 2, 2 . .4 . .──────────────────────────────────────────────────. . . ] # hit 'page-down' assume-console [ press page-down ] run [ event-loop screen, console, env, resources cursor:char <- copy 9251/ print screen, cursor ] # sandbox editor hidden; first sandbox displayed # cursor moves to first sandbox screen-should-contain [ . run (F4) . .──────────────────────────────────────────────────. . edit copy delete . .add 2, 2 . .4 . .──────────────────────────────────────────────────. . . ] # hit 'page-up' assume-console [ press page-up ] run [ event-loop screen, console, env, resources cursor:char <- copy 9251/ print screen, cursor ] # sandbox editor displays again screen-should-contain [ . run (F4) . . . .──────────────────────────────────────────────────. .0 edit copy delete . .add 2, 2 . .4 . .──────────────────────────────────────────────────. . . ] ] # page-down updates render-from to scroll sandboxes after <global-keypress> [ { page-down?:bool <- equal k, 65518/page-down break-unless page-down? sandbox:&:sandbox <- get *env, sandbox:offset break-unless sandbox # slide down if possible { render-from:num <- get *env, render-from:offset number-of-sandboxes:num <- get *env, number-of-sandboxes:offset max:num <- subtract number-of-sandboxes, 1 at-end?:bool <- greater-or-equal render-from, max break-if at-end? render-from <- add render-from, 1 *env <- put *env, render-from:offset, render-from } screen <- render-sandbox-side screen, env, render screen <- update-cursor screen, current-sandbox, env loop +next-event } ] # update-cursor takes render-from into account after <update-cursor-special-cases> [ { render-from:num <- get *env, render-from:offset scrolling?:bool <- greater-or-equal render-from, 0 break-unless scrolling? cursor-column:num <- get *current-sandbox, left:offset screen <- move-cursor screen, 2/row, cursor-column # highlighted sandbox will always start at row 2 return } ] # 'page-up' is like 'page-down': updates first-sandbox-to-render when necessary after <global-keypress> [ { page-up?:bool <- equal k, 65519/page-up break-unless page-up? render-from:num <- get *env, render-from:offset at-beginning?:bool <- equal render-from, -1 break-if at-beginning? render-from <- subtract render-from, 1 *env <- put *env, render-from:offset, render-from screen <- render-sandbox-side screen, env, render screen <- update-cursor screen, current-sandbox, env loop +next-event } ] # sandbox belonging to 'env' whose next-sandbox is 'in' # return null if there's no such sandbox, either because 'in' doesn't exist in 'env', or because it's the first sandbox def previous-sandbox env:&:environment, in:&:sandbox -> out:&:sandbox [ local-scope load-inputs curr:&:sandbox <- get *env, sandbox:offset return-unless curr, null next:&:sandbox <- get *curr, next-sandbox:offset { return-unless next, null found?:bool <- equal next, in break-if found? curr <- copy next next <- get *curr, next-sandbox:offset loop } return curr ] scenario scrolling-through-multiple-sandboxes [ local-scope trace-until 100/app # trace too long assume-screen 50/width, 20/height # initialize environment assume-resources [ ] env:&:environment <- new-programming-environment resources, screen, [] render-all screen, env, render # create 2 sandboxes assume-console [ press ctrl-n type [add 2, 2] press F4 type [add 1, 1] press F4 ] event-loop screen, console, env, resources cursor:char <- copy 9251/ print screen, cursor screen-should-contain [ . run (F4) . . . .──────────────────────────────────────────────────. .0 edit copy delete . .add 1, 1 . .2 . .──────────────────────────────────────────────────. .1 edit copy delete . .add 2, 2 . .4 . .──────────────────────────────────────────────────. . . ] # hit 'page-down' assume-console [ press page-down ] run [ event-loop screen, console, env, resources cursor:char <- copy 9251/ print screen, cursor ] # sandbox editor hidden; first sandbox displayed # cursor moves to first sandbox screen-should-contain [ . run (F4) . .──────────────────────────────────────────────────. . edit copy delete . .add 1, 1 . .2 . .──────────────────────────────────────────────────. .1 edit copy delete . .add 2, 2 . .4 . .──────────────────────────────────────────────────. . . ] # hit 'page-down' again assume-console [ press page-down ] run [ event-loop screen, console, env, resources ] # just second sandbox displayed screen-should-contain [ . run (F4) . .──────────────────────────────────────────────────. .1 edit copy delete . .add 2, 2 . .4 . .──────────────────────────────────────────────────. . . ] # hit 'page-down' again assume-console [ press page-down ] run [ event-loop screen, console, env, resources ] # no change screen-should-contain [ . run (F4) . .──────────────────────────────────────────────────. .1 edit copy delete . .add 2, 2 . .4 . .──────────────────────────────────────────────────. . . ] # hit 'page-up' assume-console [ press page-up ] run [ event-loop screen, console, env, resources ] # back to displaying both sandboxes without editor screen-should-contain [ . run (F4) . .──────────────────────────────────────────────────. .0 edit copy delete . .add 1, 1 . .2 . .──────────────────────────────────────────────────. .1 edit copy delete . .add 2, 2 . .4 . .──────────────────────────────────────────────────. . . ] # hit 'page-up' again assume-console [ press page-up ] run [ event-loop screen, console, env, resources cursor:char <- copy 9251/ print screen, cursor ] # back to displaying both sandboxes as well as editor screen-should-contain [ . run (F4) . . . .──────────────────────────────────────────────────. .0 edit copy delete . .add 1, 1 . .2 . .──────────────────────────────────────────────────. .1 edit copy delete . .add 2, 2 . .4 . .──────────────────────────────────────────────────. . . ] # hit 'page-up' again assume-console [ press page-up ] run [ event-loop screen, console, env, resources cursor:char <- copy 9251/ print screen, cursor ] # no change screen-should-contain [ . run (F4) . . . .──────────────────────────────────────────────────. .0 edit copy delete . .add 1, 1 . .2 . .──────────────────────────────────────────────────. .1 edit copy delete . .add 2, 2 . .4 . .──────────────────────────────────────────────────. . . ] ] scenario scrolling-manages-sandbox-index-correctly [ local-scope trace-until 100/app # trace too long assume-screen 50/width, 20/height # initialize environment assume-resources [ ] env:&:environment <- new-programming-environment resources, screen, [] render-all screen, env, render # create a sandbox assume-console [ press ctrl-n type [add 1, 1] press F4 ] event-loop screen, console, env, resources screen-should-contain [ . run (F4) . . . .──────────────────────────────────────────────────. .0 edit copy delete . .add 1, 1 . .2 . .──────────────────────────────────────────────────. . . ] # hit 'page-down' and 'page-up' a couple of times. sandbox index should be stable assume-console [ press page-down ] run [ event-loop screen, console, env, resources ] # sandbox editor hidden; first sandbox displayed # cursor moves to first sandbox screen-should-contain [ . run (F4) . .──────────────────────────────────────────────────. .0 edit copy delete . .add 1, 1 . .2 . .──────────────────────────────────────────────────. . . ] # hit 'page-up' again assume-console [ press page-up ] run [ event-loop screen, console, env, resources ] # back to displaying both sandboxes as well as editor screen-should-contain [ . run (F4) . . . .──────────────────────────────────────────────────. .0 edit copy delete . .add 1, 1 . .2 . .──────────────────────────────────────────────────. . . ] # hit 'page-down' assume-console [ press page-down ] run [ event-loop screen, console, env, resources ] # sandbox editor hidden; first sandbox displayed # cursor moves to first sandbox screen-should-contain [ . run (F4) . .──────────────────────────────────────────────────. .0 edit copy delete . # no change .add 1, 1 . .2 . .──────────────────────────────────────────────────. . . ] ]