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 ...)
f
suitable for a tick handler? Explain.g
be used for?k
or p
suitable handlers? If so, for what?check-expect
for the function p
.check-expect
for the function k
.The median is
the middle number in a list of sorted numbers. Write the function
median
that works for three numbers.
median: number number number -> number
Writing tests is the most important part of this exercise.
Structures
Make a structure scn
that 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 sdraw
function draws a circle with the given color, using
the number for the radius. Unless the string is square
, in
which case draw a square in the same way.
sdraw: scn -> image
Write a function scolor
that makes a new structure with the
given color, not changing any of the other fields.
scolor: scn color(new) -> scn
The scat
function 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