I.4 Semester I Review 4
Remember to practice writing check-expects for your functions, so you have a way to make progress.
-
Analyze the program segment below.
(define initial "large fluffy bunny") (define (f model) (+ 1 (string-length model))) (define (g model) (text model 25 "black")) (define (k model x y e) (string-append model x)) (define (p model w) (substring model 1)) (big-bang initial ...)- Is
fsuitable for a tick handler? Explain. - What could
gbe used for? - Are either
korpsuitable handlers? If so, for what? - Write a useful, correct
check-expectfor the functionp. - Write a useful, correct
check-expectfor the functionk.
- Is
-
The median is the middle number in a list of sorted numbers. Write the function
medianthat works for three numbers.median: number number number -> numberWriting tests is the most important part of this exercise.
-
Structures
-
Make a structure
scnthat has fields for a string, a color, and a number. -
Create an example of your structure and put it in a variable.
-
Write a function that gets the number out of your structure and adds one to it.
sincr: scn -> int -
The
sdrawfunction draws a circle with the given color, using the number for the radius. Unless the string issquare, in which case draw a square in the same way.sdraw: scn -> image -
Write a function
scolorthat makes a new structure with the given color, not changing any of the other fields.scolor: scn color(new) -> scn -
The
scatfunction takes in two structures and combines them by appending the strings and adding the numbers. The color of the result will be the same as the first structure’s color.scat: scn scn -> scn
-