I.F Semester Review F

Version 0.9

Paper Programming

(Hard pattern; work with a group.) We will work with a function fa : number -> number whose purpose is given by the check-expects below.

        (check-expect (fa   1)  0)
        (check-expect (fa  10)  1)
        (check-expect (fa  67)  6)
        (check-expect (fa 100) 11)
        (check-expect (fa 167) 17)
        (check-expect (fa 259) 27)
        (check-expect (fa 1234) 135)
  1. What pattern do you see? Discuss!
  2. Predict (fa 1289).
  3. Write a possible function fa.

Model Picking A

Explain the model to use.

A word shows on the screen. Hitting the “a” key shows “apple”, the “b” key shows “banana”, the “c” key “canteloupe”. Hitting “/” causes the animation to quit.

  1. What model would you choose?
  2. Describe what your draw handler does (one sentence).
  3. Write the function ssw? to use in the stop-when clause.

Coding

Focus: how do you do this coding with little repetition? Start by writing it however you want and then reduce the repetition by making more and more helper functions.

Six 100x100 squares are set in a row. Each has a number 11 through 16. When your mouse is in a box, the box number squared shows. Otherwise just the box number shows.

Each box has a different color.

When you click in a box, that box turns pink and the animation ends.

There is an accompanying video.

Misc: Tracing

Stepper

For this question, the order in which events occur is important, much more than the final result.

  1. Considering only the steps taken in evaluating the definition of bg, counting function calls as only one step, what are the third and fourth steps?

  2. Considering every substitution and step taken, list the first eight steps.

(define (mk-txt t) (text t 40 "black"))
(define (mk-sq c) (square 150 "solid" c))
(define (target* n)
  (cond [(= 10 n) "red"]
        [(= 20 n) "orange"]
        [(= 30 n) "yellow"]
        [(= 40 n) "green"]
        [(= 50 n) "blue"]))
(define bg (beside (mk-sq (target* 10))
                   (mk-sq (target* 20))
                   (mk-sq (target* 30))
                   (mk-sq (target* 40))
                   (mk-sq (target* 50))))
Last modified August 18, 2023: 2022-2023 End State (7352e87)