This handout covers some changes that have been put in place into the Beginning Student Language since your book was printed.
In computing, the word contract actually has a technical meaning which is different from the way it is used in the first edition.
Background: A true contract encompasses a precondition and postcondition for each function (as developed by Tony Hoare and Edsger Dijkstra) and invariants for each data structure (as developed by Hoare). The idea was popularized by Bertrand Meyer in his work on Design by Contract and the Eiffel programming language.
In COMP 50, the closest we come to true contracts is with the “purpose statement” associated with every function.
Today, when a programmer writes the name of a function and describes the input and output data, he or she is writing a signature. This word is current among programmers using C++, Java, C, Haskell, and many other languages. It is the word we will use.
The first edition tells you to “apply the function to the inputs of the examples” without ever suggesting a mechanism. The second edition provides three mechanisms: check-expect
, check-within
, and check-error
.
check-expect
is used most commonly, when you want to check a result that is a Boolean, symbol, string, image, exact number, structure, or other well-behaved data. Use check-expect
early and often.
check-within
is used only to check the results of computations with inexact numbers. Such computations include the results of functions sin
, cos
, asin
, acos
, log
, and some results of expt
(when exponents are fractional). The results of more ordinary arithmetic applied to inexact numbers are also inexact.
Use check-within
only when check-expect
fails because of inexact computations.
check-error
is used to ensure that when a function is used in a way that violates its signature, an error results. You’ll use check-error
occasionally.
For images and animations, we’ll use the second-edition teachpacks 2htdp/image
and 2htdp/universe
.
The first edition mentions strings just briefly. The second edition has a lot more stuff on strings. We’ll use strings somewhat more than in the first edition, but not as much as in the second edition.