Chris Pollett>Old Classes>PIC 15, Fall 1999>Hw5
Read SICP 316-406. Read the
Prolog handout.
Do problems: 3.58 and 3.59 out of SICP. Put your code for 3.59
in a file called hw5.scm.
Note: DrScheme does not
implement stream special forms so you will need to use MIT Scheme.
Then write a Prolog program called hw5.P which takes an input number from the user up to 1000000 and outputs its English equivalent. i.e., if the input was 105117 the program should output: one hundred and five thousand one hundred and seventeen. The predicate that runs your program should be called numbers.
Below is code from the book which might be useful to do 3.58, 3.59:
(define (display-stream s) (stream-for-each display-line s)) (define (display-line x) (newline) (display x)) (define (stream-enumerate-interval low high) (if (> low high) the-empty-stream (cons-stream low (stream-enumerate-interval (+ low 1) high)))) (define (stream-filter pred stream) (cond ((stream-null? stream) the-empty-stream) ((pred (stream-car stream)) (cons-stream (stream-car stream) (stream-filter pred (stream-cdr stream)))) (else (stream-filter pred (stream-cdr stream))))) (define (expand num den radix) (cons-stream (quotient (* num radix) den) (expand (remainder (* num radix) den) den radix)))