How to Design Programs An Introduction to Programming and Computing Matthias Felleisen download
How to Design Programs An Introduction to Programming and Computing Matthias Felleisen download
https://textbookfull.com/product/how-to-design-programs-an-
introduction-to-programming-and-computing-matthias-felleisen/
https://textbookfull.com/product/processing-an-introduction-to-
programming-1st-edition-nyhoff/
https://textbookfull.com/product/an-introduction-to-c-gui-
programming-simon-long/
https://textbookfull.com/product/introduction-to-computing-and-
programming-in-python-global-edition-mark-j-guzdial/
https://textbookfull.com/product/coding-for-beginners-or-how-to-
program-programs-with-programming-1st-edition-roger-engelbert/
Exploring Engineering: An Introduction to Engineering
and Design Philip Kosky
https://textbookfull.com/product/exploring-engineering-an-
introduction-to-engineering-and-design-philip-kosky/
https://textbookfull.com/product/python-programming-an-
introduction-to-computer-science-john-m-zelle/
https://textbookfull.com/product/multi-time-wave-functions-an-
introduction-matthias-lienert/
https://textbookfull.com/product/java-an-introduction-to-problem-
solving-and-programming-8th-edition-walter-savitch/
https://textbookfull.com/product/interface-design-an-
introduction-to-visual-communication-in-ui-design-dave-wood/
HOW TO DESIGN PROGRAMS
AN INTRODUCTION TO PROGRAMMING AND COMPUTING
SECOND EDITION
Matthias Felleisen
Robert Bruce Findler
Matthew Flatt
Shriram Krishnamurthi
Preface
Systematic Program Design
DrRacket and the Teaching Languages
Skills that Transfer
This Book and Its Parts
The Differences
I Fixed-Size Data
1 Arithmetic
1.1 The Arithmetic of Numbers
1.2 The Arithmetic of Strings
1.3 Mixing It Up
1.4 The Arithmetic of Images
1.5 The Arithmetic of Booleans
1.6 Mixing It Up with Booleans
1.7 Predicates: Know Thy Data
2 Functions and Programs
2.1 Functions
2.2 Computing
2.3 Composing Functions
2.4 Global Constants
2.5 Programs
3 How to Design Programs
3.1 Designing Functions
3.2 Finger Exercises: Functions
3.3 Domain Knowledge
3.4 From Functions to Programs
3.5 On Testing
3.6 Designing World Programs
3.7 Virtual Pet Worlds
4 Intervals, Enumerations, and Itemizations
4.1 Programming with Conditionals
4.2 Computing Conditionally
4.3 Enumerations
4.4 Intervals
4.5 Itemizations
4.6 Designing with Itemizations
4.7 Finite State Worlds
5 Adding Structure
5.1 From Positions to posn Structures
5.2 Computing with posns
5.3 Programming with posn
5.4 Defining Structure Types
5.5 Computing with Structures
5.6 Programming with Structures
5.7 The Universe of Data
5.8 Designing with Structures
5.9 Structure in the World
5.10 A Graphical Editor
5.11 More Virtual Pets
6 Itemizations and Structures
6.1 Designing with Itemizations, Again
6.2 Mixing Up Worlds
6.3 Input Errors
6.4 Checking the World
6.5 Equality Predicates
7 Summary
III Abstraction
14 Similarities Everywhere
14.1 Similarities in Functions
14.2 Different Similarities
14.3 Similarities in Data Definitions
14.4 Functions Are Values
14.5 Computing with Functions
15 Designing Abstractions
15.1 Abstractions from Examples
15.2 Similarities in Signatures
15.3 Single Point of Control
15.4 Abstractions from Templates
16 Using Abstractions
16.1 Existing Abstractions
16.2 Local Definitions
16.3 Local Definitions Add Expressive Power
16.4 Computing with local
16.5 Using Abstractions, by Example
16.6 Designing with Abstractions
16.7 Finger Exercises: Abstraction
16.8 Projects: Abstraction
17 Nameless Functions
17.1 Functions from lambda
17.2 Computing with lambda
17.3 Abstracting with lambda
17.4 Specifying with lambda
17.5 Representing with lambda
18 Summary
IV Intertwined Data
19 The Poetry of S-expressions
19.1 Trees
19.2 Forests
19.3 S-expressions
19.4 Designing with Intertwined Data
19.5 Project: BSTs
19.6 Simplifying Functions
20 Iterative Refinement
20.1 Data Analysis
20.2 Refining Data Definitions
20.3 Refining Functions
21 Refining Interpreters
21.1 Interpreting Expressions
21.2 Interpreting Variables
21.3 Interpreting Functions
21.4 Interpreting Everything
22 Project: The Commerce of XML
22.1 XML as S-expressions
22.2 Rendering XML Enumerations
22.3 Domain-Specific Languages
22.4 Reading XML
23 Simultaneous Processing
23.1 Processing Two Lists Simultaneously: Case 1
23.2 Processing Two Lists Simultaneously: Case 2
23.3 Processing Two Lists Simultaneously: Case 3
23.4 Function Simplification
23.5 Designing Functions that Consume Two Complex Inputs
23.6 Finger Exercises: Two Inputs
23.7 Project: Database
24 Summary
V Generative Recursion
25 Non-standard Recursion
25.1 Recursion without Structure
25.2 Recursion that Ignores Structure
26 Designing Algorithms
26.1 Adapting the Design Recipe
26.2 Termination
26.3 Structural versus Generative Recursion
26.4 Making Choices
27 Variations on the Theme
27.1 Fractals, a First Taste
27.2 Binary Search
27.3 A Glimpse at Parsing
28 Mathematical Examples
28.1 Newton’s Method
28.2 Numeric Integration
28.3 Project: Gaussian Elimination
29 Algorithms that Backtrack
29.1 Traversing Graphs
29.2 Project: Backtracking
30 Summary
VI Accumulators
31 The Loss of Knowledge
31.1 A Problem with Structural Processing
31.2 A Problem with Generative Recursion
32 Designing Accumulator-Style Functions
32.1 Recognizing the Need for an Accumulator
32.2 Adding Accumulators
32.3 Transforming Functions into Accumulator Style
32.4 A Graphical Editor, with Mouse
33 More Uses of Accumulation
33.1 Accumulators and Trees
33.2 Data Representations with Accumulators
33.3 Accumulators as Results
34 Summary
Epilogue: Moving On
Computing
Program Design
Onward, Developers and Computer Scientists
Onward, Accountants, Journalists, Surgeons, and Everyone Else
Index
List of Figures
Figure 1: The basic steps of a function design recipe
Figure 2: The dependencies among parts and intermezzos
Figure 3: Meet DrRacket
Figure 4: Landing a rocket (version 1)
Figure 5: Landing a rocket (version 2)
Figure 6: Landing a rocket (version 3)
Figure 7: Landing a rocket (version 4)
Figure 8: Landing a rocket (version 5)
Figure 9: Landing a rocket (version 6)
Figure 10: Laws of image creation
Figure 11: The DrRacket stepper
Figure 12: A batch program
Figure 13: How big-bang works
Figure 14: A first interactive program
Figure 15: From information to data, and back
Figure 16: The completion of design step 5
Figure 17: Testing in BSL
Figure 18: The wish list for designing world programs
Figure 19: Examples for a moving car program
Figure 20: Recall from “One Program, Many Definitions”
Figure 21: Conditional functions and special enumerations
Figure 22: UFO, descending
Figure 23: Rendering with a status line
Figure 24: Rendering with a status line, revised
Figure 25: Launching a countdown and a liftoff
Figure 26: How a traffic light functions
Figure 27: A symbolic traffic light
Figure 28: A transition diagram for a door with an automatic closer
Figure 29: A Cartesian point
Figure 30: The universe of data
Figure 31: Adding structure to a universe
Figure 32: Rendering space invader game states, by example
Figure 33: The complete rendering function
Figure 34: Rendering game states again
Figure 35: Rendering the space invader games, with tanks
Figure 36: Two ways of writing a data definition for FSMs
Figure 37: A finite state machine as a diagram
Figure 38: The universe of BSL data
Figure 39: BSL core vocabulary
Figure 40: BSL core grammar
Figure 41: Syntactic naming conventions
Figure 42: Replacing equals by equals
Figure 43: BSL, full grammar
Figure 44: Building a list
Figure 45: Drawing a list
Figure 46: List primitives
Figure 47: Searching a list
Figure 48: Computing with lists, step 1
Figure 49: Computing with lists, step 2
Figure 50: Computing with lists, step 3
Figure 51: Arrows for self-references in data definitions and
templates
Figure 52: How to translate a data definition into a template
Figure 53: How to turn a template into a function definition
Figure 54: Turning a template into a function, the table method
Figure 55: Tabulating arguments, intermediate values, and results
Figure 56: Designing a function for self-referential data
Figure 57: A table for cat
Figure 58: A table for sorted>?
Figure 59: Creating a list of copies
Figure 60: Random attacks
Figure 61: A list-based world program
Figure 62: Two data representations for sets
Figure 63: Functions for the two data representations of sets
Figure 64: Computing the wages of all employees
Figure 65: Computing the wages from work records
Figure 66: Things take time
Figure 67: Reading files
Figure 68: Counting the words on a line
Figure 69: Encoding strings
Figure 70: Transpose a matrix
Figure 71: Tabulating for rev
Figure 72: Sorting lists of numbers
Figure 73: Drawing a polygon
Figure 74: Reading a dictionary
Figure 75: Representing iTunes tracks as structures (the structures)
Figure 76: Representing iTunes tracks as structures (the functions)
Figure 77: Representing iTunes tracks as lists
Figure 78: Finding alternative words
Figure 79: Playing Worm
Figure 80: Random placement of food
Figure 81: Simple Tetris
Figure 82: Representing and interpreting finite state machines in
general
Figure 83: A simplistic HTML generator
Figure 84: A data representation based on nested lists
Figure 85: A web page generated with BSL+
Figure 86: Two similar functions
Figure 87: Two similar functions, revisited
Figure 88: Two more similar functions
Figure 89: Finding the inf and sup in a list of numbers
Figure 90: A pair of similar functions
Figure 91: The same two similar functions, abstracted
Figure 92: The similar functions for exercise 250
Figure 93: The similar functions for exercise 251
Figure 94: The similar functions for exercise 252
Figure 95: ISL’s abstract functions for list processing (1)
Figure 96: ISL’s abstract functions for list processing (2)
Figure 97: Creating a program with abstractions
Figure 98: Organizing a function with local
Figure 99: Organizing interconnected function definitions with local
and
A student of design who never touches a program again will still pick
up universally useful problem-solving skills, experience a deeply
creative activity, and learn to appreciate a new form of aesthetic. The
rest of this preface explains in detail what we mean with “systematic
design,” who benefits in what manner, and how we go about teaching
it all.
We drew inspiration from Michael Jackson’s method for creating COBOL programs plus
conversations with Daniel Friedman on recursion, Robert Harper on type theory, and
Daniel Jackson on software design.
Instructors Have students copy figure 1 on one side of an index card. When students
are stuck, ask them to produce their card and point them to the step where they are
stuck.
Instructors The most important questions are those for steps 4 and 5. Ask students
to write down these questions in their own words on the back of their index card.
The novelty of this approach is the creation of intermediate
products for beginner-level programs. When a novice is stuck, an
expert or an instructor can inspect the existing intermediate products.
The inspection is likely to use the generic questions from the design
process and thus drive the novice to correct himself or herself. And
this self-empowering process is the key difference between
programming and program design.
Iterative Refinement addresses the issue that problems are
complex and multifaceted. Getting everything right at once is nearly
impossible. Instead, computer scientists borrow iterative refinement
from the physical sciences to tackle this design problem. In essence,
iterative refinement recommends stripping away all inessential details
at first and finding a solution for the remaining core problem. A
refinement step adds in one of these omitted details and re-solves
the expanded problem, using the existing solution as much as
possible. A repetition, also called an iteration, of these refinement
steps eventually leads to a complete solution.
In this sense, a programmer is a miniscientist. Scientists create
approximate models for some idealized version of the world to make
predictions about it. As long as the model’s predictions come true,
everything is fine; when the predicted events differ from the actual
ones, scientists revise their models to reduce the discrepancy. In a
similar vein, when programmers are given a task, they create a first
design, turn it into code, evaluate it with actual users, and iteratively
refine the design until the program’s behavior closely matches the
desired product.
This book introduces iterative refinement in two different ways.
Since designing via refinement becomes useful even when the design
of programs becomes complex, the book introduces the technique
explicitly in the fourth part, once the problems acquire a certain
degree of difficulty. Furthermore, we use iterative refinement to state
increasingly complex variants of the same problem over the course of
the first three parts of the book. That is, we pick a core problem, deal
with it in one chapter, and then pose a similar problem in a
subsequent chapter—with details matching the newly introduced
concepts.
DrRacket and the Teaching Languages
Learning to design programs calls for repeated hands-on practice.
Just as nobody becomes a piano player without playing the piano,
nobody becomes a program designer without creating actual
programs and getting them to work properly. Hence, our book comes
with a modicum of software support: a language in which to write
down programs and a program development environment with which
programs are edited like word documents and with which readers can
run programs.
Many people we encounter tell us they wish they knew how to
code and then ask which programming language they should learn.
Given the press that some programming languages get, this question
is not surprising. But it is also wholly inappropriate. Learning to
program in a currently fashionable programming language often sets
up students for eventual failure. Fashion in this world is extremely
short lived. A typical “quick programming in X” book or course fails to
teach principles that transfer to the next fashion language. Worse,
the language itself often distracts from the acquisition of transferable
skills, at the level of both expressing solutions and dealing with
programming mistakes.
Instructors For courses not aimed at beginners, it may be possible to use an off-the-
shelf language with the design recipes.
Instructors You may wish to explain that BSL is pre-algebra with additional forms of
data and a host of pre-defined functions on those.
III
CONSEQUENCES OF CARRIAGE OF CONTRABAND
CHAPTER V
UNNEUTRAL SERVICE
I
THE DIFFERENT KINDS OF UNNEUTRAL SERVICE
II
CONSEQUENCES OF UNNEUTRAL SERVICE
I
VISITATION
Visit.
§ 420. The vessel, having been stopped or brought to, is
visited[896] by one or two officers sent in a boat from the man-of-war.
These officers examine the papers of the vessel to ascertain her
nationality, the character of her cargo and passengers, and, lastly,
the ports from and to which she is sailing. Instead of visiting the
merchantman and inspecting her papers on board, the practice is
followed, by the men-of-war of some States, of summoning the
master of the merchantman with his papers on board the former and
examining the papers there.
[896] See above, vol. I. § 268, and Holland, Prize Law, §§ 195-216.
If everything is found in order and there is no suspicion of fraud,
the vessel is allowed to continue her course, a memorandum of the
visit having been entered in her log-book. On the other hand, if the
inspection of the papers shows that the vessel is carrying
contraband or rendering unneutral service, or that she is for another
reason liable to capture, she is at once seized. But it may be that,
although ostensibly everything is in order, there is nevertheless
grave suspicion of fraud against the vessel. In such case she may be
searched.
Search.
§ 421. Search is effected[897] by one or two officers, and eventually
a few men, in presence of the master of the vessel. Care must be
taken not to damage the vessel or the cargo, and no force whatever
must be applied. No lock must be forcibly broken open by the search
party, but the master is to be required to unlock it. If he fails to
comply with the demand he is not to be forced thereto, since the
master's refusal to assist the search in general, or that of a locked
part of the vessel or of a locked box in particular, is at once sufficient
cause for seizing the vessel. Search being completed, everything
removed has to be replaced with care. If the search has satisfied the
searching officers and dispelled all suspicion, a memorandum is
entered in the log-book of the vessel, and she is allowed to continue
her voyage. On the other hand, if search brought contraband or
another cause for capture to light, the vessel is seized. But since
search can never take place so thoroughly on the sea as in a
harbour, it may be that, although search has disclosed no proof to
bear out the suspicion, grave suspicion still remains. In such case
she may be seized and brought into a port for the purpose of being
searched there as thoroughly as possible. But the commander of a
man-of-war seizing a vessel in such case must bear in mind that full
indemnities must be paid to the vessel for loss of time and other
losses sustained if finally she is found innocent. Therefore, after a
search at sea has brought nothing to light against the vessel, seizure
should take place only in case of grave suspicion.
[897] See above, vol. I. § 269, and Holland, Prize Law, §§ 217-230.
Deficiency of Papers.
§ 426. Since the purpose of visit is to ascertain the nationality of a
vessel, the character of her cargo and passengers, and the ports
from and to which she is sailing, it is obvious that this purpose
cannot be realised in case the visited vessel is deficient in her
papers. As stated above in Vol. I. § 262, every merchantman ought
to carry the following papers: (1) A certificate of registry or a sea-
letter (passport); (2) the muster-roll; (3) the log-book; (4) the
manifest of cargo; (5) bills of lading, and (6) if chartered, the
charter-party. Now, if a vessel is visited and cannot produce one or
more of the papers mentioned, she is suspect. Search is, of course,
admissible for the purpose of verifying the suspicion, but it may be
that, although search has not produced any proof of guilt, the
suspicion is not dispelled. In such case she may be seized and
brought to a port for thorough examination. But, with the exception
of the case that she cannot produce either certificate of registry or a
sea-letter (passport), she ought not to be confiscated for deficiency
in papers only. Yet, if the cargo is also suspect, or if there are other
circumstances which increase the suspicion, confiscation would be, I
believe, in the discretion of the Prize Court.
The Declaration of London does not mention the point, and the
International Prize Court would, therefore, have to evolve a system
of rules to be applied in cases concerned.
Spoliation, Defacement, and Concealment of Papers.
§ 427. Mere deficiency of papers does not arouse the same
suspicion which a vessel incurs if she destroys[905] or throws
overboard any of her papers, defaces them or conceals them, and in
especial in case the spoliation of papers takes place at the time
when the visiting vessel comes in sight. Whatever her cargo may be,
a vessel may at once be seized without further search so soon as it
becomes apparent that spoliation, defacement, or concealment of
papers has taken place. The practice of the several States has
hitherto differed with regard to other consequences of spoliation,
and the like, of papers, but confiscation is certainly admissible in
case other circumstances increase the suspicion.[906]
[905] The Hunter (1815), 1 Dodson, 480.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com