We are continuing our stroll through the Prologue of HtDP2e.
(When we have finished this stroll, you will know much of the language. Then we will start over and talk about a more systematic way of designing programs.)
-
Compute the sum of 10, 20 and 30.
-
Multiply 48 384 by 2 091.
-
Divide a billion iby a thousand.
-
Try evaluating
1/2(just as written, not(/ 1 2)). What about2/3? What about2 / 3? What's going on? -
The speed of light is 3×108 m/s; it is 93 million miles from the earth to the sun; and a mile is about 8/5 km. How long does it take the light from the sun to reach the earth?
(Try to do this all in one expression.)
-
Temperatures in Celsius, C, can be converted to Fahrenheit, F, with the following formula: C = (5/9)×(F−32). What is 37.5 degrees Celsius in Fahrenheit?
-
What is the difference between
12and(12)? What happens if you ask Racket to evaluate each? Can you explain the error message?
We saw two ways to make expressions. Either:
-
A value; or
-
(functionarg1arg2 ...)
where the args are also expressions. And so far, "a value" has meant "a
number". (This is not the whole truth!)
-
Other kinds of value.
-
Other functions (on those new kinds of values).
-
(Perhaps) Definitions.
- Numbers (
42) - Strings (
"Hello, World.") - Truth (
#true,#false) (these are called "Booleans", after George Boole) - Images
Try the following. Before each, try to say what you expect to happen.
"Hello, World."(string-length "Hello, World.")(string-append "Hello" "World.")(string-append "Hello" ", " "World" ".")(string-append "Hello" 42)(string-length "Hello, World.")(string=? "Hello" "World")(string=? "Hello" "hello")(string=? "Hello" "Hello ")(number->string 42)(= 1 2)(= 2 2)(> 2 1)(and #true #false)(or #true #false #false)