6.7

Week 9 Set a

home work!

Programming Language ISL

Due Date Mon at 9pm (Week 9)

Purpose To practice the design of functions on multi-recursive data definitions

Finger Exercises

Exercise 1 From HtDP, 319, 320, and 323.

Graded Exercises

Exercise 2 Exchanging code across networks is unsafe at any speed. Developers nevertheless base communication protocols on this idea and use inherently evil constructs such as eval functions (embedded interpreters for general-purpose languages).

In this spirit, imagine the following scenarios. The users of your chat room clients clamor for ways to send instructions to each others clients. Specifically, they want to send instructions to draw imagines into their friends clients.

The head programmers of chat.com have designed a data definition to accommodate this wish:
; A PD (short for picture description) is one of:
;  'empty-image
;  String
;  (list 'circle Number String String)
;  (list 'rectangle Number Number String String)
;  (list 'beside PD PD)
;  (list 'above PD PD)
Instead of using the ISL interpreter directly in the extended chat client, they want you to design the function pd-interpret. The function consumes a PD and produces the corresponding image. The function interprets strings as 12-point text images in blue.

Your manager has also supplied the following helper functions:
(define (empty-image? i) (symbol? i))
(define (circle? i) (and (cons? i) (symbol=? (first i) 'circle)))
(define (rectangle? i) (and (cons? i) (symbol=? (first i) 'rectangle)))
(define (above? i) (and (cons? i) (symbol=? (first i) 'above)))
(define (beside? i) (and (cons? i) (symbol=? (first i) 'beside)))
 
(define circle-radius second)
(define circle-mode third)
(define circle-color fourth)
 
(define rectangle-width second)
(define rectangle-height third)
(define rectangle-mode fourth)
(define rectangle-color fifth)
 
(define above-top second)
(define above-bot third)
 
(define beside-left second)
(define beside-right third)
They provide the illusion that your data representation uses nested structures instead of S-expressions. You may use them if you figure out the underlying assumptions.

Note When one of your friends sends you a picture in an app, what is really transmitted are instructions such as PDs. Of course, there is also software that takes pictures and turns them into such codes, i.e., digital cameras, so that nobody has to type in these codes.