22b. List Exercises 7
A few more exercises using lists.
-
(
col-gen: number(x) number(ymax) -> list-of-posn
) The column generator. Given an x-coordinate and maximum y-coordinateymax
, make a list of posns with that x-coordinate whose y-coordinate counts down fromymax
to 0.(check-expect (col-gen 5 3) (list (make-posn 5 3) (make-posn 5 2) (make-posn 5 1) (make-posn 5 0)))
-
(
circler: list-of-posns image -> image
) Take in a list of posns $(x,y)$ and a background image and put out a list of circles of radius 8 at coordinates $(10x, 10y)$ on the background.(define CIRC (circle 8 "solid" "black")) (define BG (empty-scene 300 200)) (check-expect (circler (list (make-posn 1 2) (make-posn 5 8)) BG) (place-image CIRC 10 20 (place-image CIRC 50 80 BG)))
-
(
zap-first
) Given an x-coordinate and a list of posns, remove the first posn in the list with that given x-coordinate.(check-expect (zap-first 5 (list (make-posn 5 3))) empty) (check-expect (zap-first 5 (list (make-posn 4 6) (make-posn 5 3))) (list (make-posn 4 6))) (define demo-list (list (make-posn 5 8) (make-posn 7 1) (make-posn 6 9) (make-posn 7 0))) (check-expect (zap-first 7 demo-list) (list (make-posn 5 8) #;(removed 7 1) (make-posn 6 9) (make-posn 7 0)))