Remember:
(define-struct stage (is-below))
;; An LV is one of:
;; -- 'capsule
;; -- (make-stage LV)
Exercise 1: Write down some
examples of LV
s.
Exercise 2: Write the
template for LV
.
Change roles after
Exercise 3: Write a
function called count
that takes a list of symbols and
produces the length of the list. Run the function on a few examples
of different sizes, and use the Stepper to see the steps that
evaluation takes.
Exercise 4: Design a function that takes a list of symbols and a symbol and returns a list like the original list but with the given symbol added to the end.
Exercise 5: Design a
function that takes a list of numbers and a number n
and
returns a list of all the numbers larger than n
.
;; A list-of-bills is one of:
;; -- empty
;; -- (cons (make-bill string number) list-of-bills)
(define-struct bill (customer amount))
Write down some example lists of bills. Then write the template for functions consuming a list of bills.
Exercise 6: Design a function that takes a list of bills and computes the sum of all the bill amounts.
Exercise 7: Design a function that takes a list of bills and computes the number of bills in the list. (Hint: your solution to exercise 3 is a good starting point).
Exercise 8: Design a function that takes a list of bills and computes the average amount owed. (Hint: use functions you have already written!).
Exercise 9: Design a function that takes a list of bills and produces a list of all the customer names.
Here is the data definition for a list of stock trades:;; A list-of-trades is one of:
;; -- empty
;; -- (cons (make-stock-sale symbol number number) list-of-trades)
;; -- (cons (make-stock-purchase symbol number number) list-of-trades)
(define-struct stock-sale (company shares price-per-share))
(define-struct stock-purchase (company shares price-per-share))
Exercise 10: Design a function that takes a list of stock trades and returns a list of the traded companies (that is, their stock symbols).
Exercise 11: Design a function that takes a list of stock trades and a symbol and returns the total value of traded shares (both bought and sold).
Here are some data definitions for weather reports:;; A weather-report is (make-weather-report date number)
(define-struct weather-report (date avg-temp))
;; A date is (make-date number number number)
(define-struct date (year month day))
Exercise 12: Design a
function that takes a list of weather reports, a number low
,
and a number high
, and produces a list of low
and high
.
Exercise 13: Design a function that takes a list of weather reports and returns a list of numbers containing the average temperature for each day.
Exercise 14: Design a function that takes a list of weather reports and two dates and produces a list of all the weather reports with dates between those two dates.