Modules

Course links

Exercise 1

Write a Scheme program that invokes the binomial-coefficients module presented in today's reading and uses it to find out how many ways there are to choose five cards from a pack of fifty-three.

Exercise 2

Look back at the shirt-definition.ss file that you created in exercise 4 of the metaprogramming lab. Open that file in a Definitions window in DrScheme and convert its contents into a declaration for a module called shirt-definition by adding appropriate enclosing lines at the beginning and end. Write a Scheme program that invokes the shirt-definition module and uses the imported constructor procedure to create an inventory record for seventeen purple shirts in size M, catalog number 44102R, priced at $28.50.

Exercise 3

The file math.ss in the PLT Scheme mzlib collection contains a module declaration that exports the constants pi and e and a selection of occasionally useful mathematical procedures such as sqr (which computes and returns the square of its argument). Write a require-expression that invokes this module to import those constants and procedures, but prefixes math: to the name of each one. Use the resulting identifiers to have Scheme compute the square of pi.

Exercise 4

Collect the definitions for some general procedures that you've found helpful in previous labs and programming assignments and make a module of them. (If you have no particular preferences, use the definitions of square and sum for the sake of the example.) Save your module in a file.

A DrScheme teachpack is actually just a file that contains the declaration for a module that is automatically invoked when the Run button is clicked. Use the ``Add Teachpack...'' option in DrScheme's Language menu to add your module as a teachpack.