- Write brief answers for each of the following items.
(One phrase or code expression is usually sufficient for each
- One of the three things that every programming language has
is a means of combination. What is Racket's only
means of combination? Give an example to illustrate your
- What are the other two things that every programming language
has? Give an example of each from Racket.
- We say that define is a special form. What
does that mean? List one way we can know that is true from
- What does it mean to say that a function is variable
- Answer each of these questions about the structure of Racket
- Write a Racket function named line-item-cost that
takes three arguments, all numbers: the number of items being
purchased, the price per item, and the sales tax rate.
line-item-cost returns the total cost for this
purchase, including sales tax. For example:
> (line-item-cost 1 1.00 0.05) ; 1 x $1.00, plus 5%
> (line-item-cost 4 5.00 0.07) ; 4 x $5.00, plus 7%
> (line-item-cost 6 10.00 0.15) ; 6 x $10.00, plus 15%
You may write a helper function, but do not have to.
- Write a Racket function named fun-less-than that
takes two arguments, functions f and g. Both
f and g take a single integer argument.
fun-less-than returns a function of one argument, an
integer n. The returned function computes the value
f(n) < g(n). For example:
> (define double (lambda (n) (* n 2)))
> (define square (lambda (n) (* n n)))
> (define 2n+1 (lambda (n) (add1 (double n))))
> ((fun-less-than double square) 2) ; is (2*2) < (2*2)?
> ((fun-less-than double square) 5) ; is (5*2) < (5*5)?
> (define 2n+1<n²? (fun-less-than 2n+1 square))
> (2n+1<n²? 5) ; because 11 < 25
> (2n+1<n²? 2) ; because 5 is not < 4
You'll earn a bonus point if you don't use an if or a
cond in your solution. Boolean values are values,
- Suppose that we have a list of pixels from an image, where each
pixel is a list (r g b) containing the red, green, and
blue (RGB) values of the pixel:
( (76 195 202) (255 71 208) (175 81 214) (0 165 81) ... )
Write a Racket function named least-red-green that
takes one argument, a list of pixels lst in this form.
least-red-green computes the sum of the red and
green values for every pixel in lst and returns the
smallest of the sums. For example:
> (least-red-green '((1 3 5)))
; the red + green sums are 220 and 480, respectively
> (least-red-green '((100 120 140) (240 240 240)))
; trust me: this pixel has smallest red + green ||||||
> (least-red-green '((76 195 202) (255 71 208) (175 81 214)))
Use the higher-order functions apply and
map as needed to implement your function.
No recursion or looping are allowed!
You will want to use Racket's variable-arity
min function in your solution.