For 1.4
The review section contains a mix of “sequence-making” commands like
in-range
and lists. When the question gives a sequence-making command,
write the list it will produce. When the question gives a list, write
a sequence-making command that could be used to produce it.
To write list answers, give the first three items, then ...
to the
last item. The long list:
(list 21 22 23 24 25 26 27 28 29 30)
should be written:
(list 21 22 23 ... 30)
Short Answer Review
-
(list 0 1 2 3 ... 19)
-
(in-range 40)
-
(in-range 0 9)
-
(list 5 6 7 8 9 10 11)
-
(in-range 19 29)
-
(list 0 2 4 6 8)
-
(list 10 200 30)
-
Given the list
XC
, create a list of radius 20 solid circles with those colors.(define XC (list "red" "blue" "orange" "purple"))
-
(list 100 99 98 ... 1)
Complete For Loops
- Make this list:
(list "100 bottles of beer on the wall"
"99 bottles of beer on the wall"
"98 bottles of beer on the wall"
...
"1 bottles of beer on the wall"
)
-
Make a list of all of the odd numbers 1 through 101 that are not divisible by 7. The omitted numbers are marked
#;NO-
. Do not generate anything for your missing numbers.(list 1 3 5 #;NO-7 9 11 13 15 17 19 #;NO-21 23 ... 99 101)
Newer Material: in-naturals
Understanding in-naturals
and two variable for-loops makes these a
lot easier.
-
Starting with the list
XC
from above, produce the list:(list (triangle 125 "solid" "red") (triangle 150 "solid" "blue") (triangle 175 "solid" "orange") (triangle 200 "solid" "purple"))
Now complete the For Exercises 1.5.
Newer Material: for/fold
The original review included two examples of for/fold.
Folding: Adding
You have 3 dollars. On your way to school, you find a quarter, a dime, another dime, and 7 pennies. How much do you have?
(define FOUND (list 0.25 0.10 0.10 0.01 0.01 0.01 0.01 0.01 0.01 0.01))
(for/fold ([money 3.00])
([coin (in-list FOUND)])
(+ money coin))
Folding: Drawing
You need a circle at each location in list.
(define C (circle 20 "outline" "black"))
(define PTS (list (make-posn 100 40) (make-posn 110 20) (make-posn 180 50)))
(for/fold ([pic (empty-scene 200 100)])
([p (in-list PTS)])
(place-image C (posn-x p) (posn-y p) pic))
Note on Length
This material can be covered in a 90 minute class.