To make sure you can write programs with streams.
To make sure you can convert programs so that all calls to scripts are in script position.
Write a program make-square-stream that produces an
infinite stream of squares (1, 4, 9, 16, ...). Do this without
using the stream-cons and stream-rest definitions from
class (and don't define similar helpers/macros for yourself). I want
to make sure you understand how streams work and are built without
relying on these helpers. Assume that all you have is the
stream-struct: (define-struct stream (first make-rest)).
Convert each of the following programs such that all calls to scripts are in script-position.
(define (fscript x) (+ 3 (* 2 x))) (define (gscript y z) (+ (* y y) (* z z))) (fscript (gscript (fscript 7) 8))
(define (square-script x) (* x x))
(define (tri-height x) (sqrt (- (square-script x) (square-script (* .5 x)))))
(define (shape-area shape-type size)
(cond [(symbol=? shape-type 'circle) (* pi (square-script size))]
[(symbol=? shape-type 'square) (square-script size)]
[(symbol=? shape-type 'equilat-tri) (* size (tri-height size))]))
;; assume that fscript could be rewritten as fscript/web, taking an action
;; as a second argument
(define (map fscript L)
(cond [(empty? L) empty]
[(cons? L) (cons (fscript (first L))
(map fscript (rest L)))]))
(define (prompt-read promptstr)
(begin
(printf "~a: " promptstr)
(read)))
(define (prompt-script plist)
(cond [(empty? plist) empty]
[(cons? plist)
(cons (prompt-read (first plist))
(prompt-script (rest plist)))]))
Turn in a single file hwk7.ss (or hwk7.scm) containing all code and documentation for this assignment. Make sure that both students' names are in a comment at the top of the file.
Refer to the Laws of Homework when preparing your solutions.