For 0.5
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)
Range
Instructions
This section contains a mix of “stream-making” commands like
in-range
and lists. When the question gives a stream making command,
write the list it will produce. When the question gives a list, write
a stream-making command that could be used to produce it.
Short Exercises
(in-range 30)
(in-range 5 28)
(in-range 5 28 10)
(list 0 1 2 3)
(list 80 81 82 83 84 85 86 87)
(list 70 77 84 91 98 105)
(list 16 15 14 13 12 11 10 9)
([y (in-range 30)] #:when (zero? (remainder y 8)))
Full Example, Explained
In the code below:
y
runs through the integers 0, 1, … 29;- it contributes to the answer when the remainder of
y
divided by 8 is zero — that is,y
is a multiple of 8; and - each of these
y
values produces an outline black triangle in the final list.
(for/list ([y (in-range 30)]
#:when (zero? (remainder y 8)))
(triangle (+ y 20) "outline" "black"))
Complete Exercises
-
As part of making a simple graphing calculator app, you need a list of posns
(x,x^2)
asx
goes from -10 through 10. Write code to make that list. -
Given the definition:
(define WO (list "red" "green" "blue"))
produce the list
(list "Color is red" "Color is green" "Color is blue")
-
Given the definitions:
(define ALPHA "abcdefghijklmnop") (define NS (list 2 0 11 5))
Produce a list where the number n from NS gives the letter at index N in
ALPHA
, so(list "c" "a" "l" "f")
in this case. -
Given the definition:
(define PN (list pic:hacker pic:book pic:calendar pic:bloch))
Create a list where each image has a 25 pixel high solid light blue rectangle underneath it. The width of the rectangle should match the width of the image.