Converting Numbers to Words (team assignment)

Scheme can represent numbers in a variety of forms, including integer, rational, real, and complex. Let's add a new form: English. That is, we will allow numbers to be represented as a list of symbols representing English language words corresponding to numbers. Thus the numeral 0 would be represented as (zero), 123 as (one hundred twenty three) and -456789 as (minus four hundred fifty six thousand seven hundred eighty nine).

Assume that we represent numbers (in English) using the symbols minus, zero, one, two, ..., ten, eleven, twelve, ..., nineteen, twenty, thirty, ..., ninety, hundred, thousand, million, ... For simplicity, numbers that are normally hyphenated (like twenty-three) won't be.

(a) Write a Scheme function (int->eng int-val) that converts an integer int-val into English form (that is, a list of symbols representing the number in English). Your function should handle numbers at least as large as one trillion (handling even larger numbers is fairly easy). For numbers larger than your implementation limit (of one trillion or more) you may return the integer unconverted. You may find the Scheme functions quotient, remainder, expt, and/or abs useful.

(b) Now write an inverse function (eng->int L) that converts a number in English form back to integer form. Of course it should be the case that

(eng->int (int->eng int-val)) = int-val

for all integers in the range you handle. You may assumed that this number in English is well-formed.

(c) Finally, redefine the +, -, *, and quotient functions so that they accept numbers in English form as well as integer form (you may ignore numbers in rational, real, and complex forms). You may assume that your extended operators will be called with only two operands. If both operands are in integer form, then you will return in an integer result. If one or both are in English form, then you will return a result in English form. For /, you may use truncate to convert fractional quotients to integers; that is, you need not worry about divisions that have a non-zero remainder.

The following are sample calls that you should handle:

(+ 123 456) ---> 579

(- 111111 '(ten)) ---> (one hundred eleven thousand one hundred one)

(* '(two thousand fifty five) '(one million one))
  ---> (two billion fifty five million two thousand fifty five)

(quotient 123456789 '(three)) --->
  (forty one million one hundred fifty two thousand
   two hundred sixty three) 

Note that redefining the built in arithmetic operations is in general dangerous (but fun for our purposes!). Once you start playing with this, be aware that you may need to quit DrScheme and restart it each time that you run your code. Note that if you redefine the symbol +, you may want to first assign another symbol to refer to the addition function.


You must use recursion, and not iteration. You may not use side-effects (e.g. set!).

Submit your code in a file called numbers2words.scm.