1. About "make-color"
(define (clarify-color c)
(make-color
(color-red c)
(color-green c)
(color-blue c)
(cond
[(> (+ (color-red c) (color-green c) (color-blue c)) 650) 0]
[else (color-alpha c)])))
I have to make a "check-expect" basing on the above,
at first I tried putting the entire function "(make-color 1 2 3 0)" to c.
However, this can actually be done very easily.
(check-expect (clarify-color (make-color 0 0 255 0))
(make-color
0
0
255
0
))
2. Clarify-image
I got stuck for more than 4 hours on fixing the function "clarify-image".
After looking back and working on the previous exercise "map and map-image", I got this function working finally!
An example from the exercise "mapping",
(map-image less-green "pic: hacker")
To define a function by using another function, which is the "clarify-color", I had to use the "map-image".
Here is what I did at last,
(define (clarify-image im) (map-image clarify-color im))
3. Set-clock
After fixing the function "set-clock",
(define (set-clock h m s s/g) (make-clocktime h m s s/g))
I had to make two "check-expect" for the function.
It might somehow seem easy for the others after they've looked at your work;
however, to have every next function working fine, you always have to trace back and truly understand every steps.
Without studying the above functions, you might not know h=hours, m=minutes, s=seconds, s/g=STOP/GO;
and you as well might not know what "make-clocktime" is.
This is one of the check expect,
(check-expect (set-clock 6 7 8 STOP) (make-clocktime 6 7 8 STOP))
4. check-key
I had to fix the function "check-key" by following the hints from the "check-expect".
I had spent quite a while on this as I was so confused about what to do with the last section "s/g".
But at last, I found that it could actually be done very simply, it's just that I had been thinking in a too complicated way.
(check-expect (check-key (make-clocktime 1 2 3 GO) "down") (make-clocktime 1 2 3 STOP))
(define (check-key c k)
(cond
[(equal? k "down")
(make-clocktime
(clocktime-hours c)
(clocktime-minutes c)
(clocktime-seconds c)
STOP)]
[else c]))
To sum up, I think I have learnt a lot after doing the project. It is just kind of like a revision, helping clarifying everything we have been learning.
No comments:
Post a Comment