In farming and gardening, it is sometimes desirable to add or restore nutrients to the soil by adding not only humus (decaying plant matter) but also some kind of fertilizer. Chemical fertilizers promote growth, but they are highly concentrated, and applying the wrong dose or failing to spread it out evenly enough can cause actual damage to the roots of plants, kill beneficial microorganisms in the soil, and drive away earthworms that aerate and mix the soil. For this reason, many gardeners prefer to use organic fertilizers made from bone meal, old coffee grounds, wood ashes, and so on.
Because a single organic material does not necessarily provide nutrients in the correct relative proportions, it is usual to mix them together -- combining, for instance, bone meal (which is high in phosphorus), cottonseed meal (high in nitrogen), and wood ashes (high in potassium) in appropriate amounts. The program that you'll be looking at today allows the user to compute the percentage (by weight) of various nutrients in any specified mixture of materials commonly used in organic fertilizers.
The Scheme program containing the procedures that carry out these computations can be found at /home/stone/courses/scheme/html/fertilizer-project.ss. Copy this file into your home directory by opening a dtterm window and giving the shell command
cp /home/stone/courses/scheme/html/fertilizer-project.ss ~/fertilizer-project.ss
Unfortunately, the program doesn't work:
> (nitrogen-percentage high-nitrogen-mix) Error in car: blood-meal is not a pair. Type (debug) to enter the debugger.
Find and correct the errors in the program.
Extend the program by writing a procedure that takes two arguments -- a recipe for a particular mix of fertilizer and the weight (in kilograms) of the amount of fertilizer to be made up from that recipe -- and computes and returns the weight (in kilograms) of each of the organic materials in the recipe.
This document is available on the World Wide Web as
http://www.math.grin.edu/courses/Scheme/spring-1998/fertilizer-project.html
created February 22, 1998
last revised June 21, 1998