22b. List Exercises 7

A few more exercises using lists.
  1. (col-gen: number(x) number(ymax) -> list-of-posn) The column generator. Given an x-coordinate and maximum y-coordinate ymax, make a list of posns with that x-coordinate whose y-coordinate counts down from ymax 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)))
    
  2. (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)))
    
  3. (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)))
    
Last modified August 18, 2023: 2022-2023 End State (7352e87)