;;; defines global variable interpreter-defn-table and its access functions (define interpreter-defn-table ( )) (define (add-interpreter-defn name closure) (set! interpreter-defn-table ;; your code here ******** )) (define (lookup-interpreter-defn name) (cdr (assoc name interpreter-defn-table))) ;;; ------------------------------------------------------------ ;;; the interpreter ;;; return the state of the dot at coordinates (x, y) ;;; #t = #, #f = . (define (interpret x y expr) (if (list? expr) (let ((handler (lookup-interpreter-defn (car expr)))) (apply handler x y (cdr expr))) expr)) (define (do-block x y width height) (if (and (> x 0) (<= x width) (> y 0) (<= y height)) #t #f)) (add-interpreter-defn 'block do-block) (define (do-triangle x y size direction) ;; your code here ******** ) (add-interpreter-defn 'triangle do-triangle) (define (do-pastey x y shape1 shape2 y-offset) (if (<= y y-offset) (interpret x y shape1) (interpret x (- y y-offset) shape2))) (add-interpreter-defn 'pastey do-pastey) (define (do-pastex x y shape1 shape2 x-offset) ;; your code here ******** ) (add-interpreter-defn 'pastex do-pastex) (define (do-reflectx x y shape x-center) ;; your code here ******** ) (add-interpreter-defn 'reflectx do-reflectx) (define (do-reflecty x y shape y-center) ;; your code here ******** ) (add-interpreter-defn 'reflecty do-reflecty) ;;; ------------------------------------------------------------ ;;; defines global variable compiler-defn-table and its access functions (define compiler-defn-table ( )) (define (add-compiler-defn name closure) (set! compiler-defn-table ;; your code here ******** )) ) (define (lookup-compiler-defn name) (cdr (assoc name compiler-defn-table))) ;;; ------------------------------------------------------------ ;;; the compiler ;;; return a closure that returns the state of the dot at coordinates (x, y) ;;; #t = #, #f = . (define (compile expr) (if (list? expr) (let ((handler (lookup-compiler-defn (car expr))) ) (apply handler (cdr expr))) expr)) (define (compile-block width height) (display (list 'running 'compile-block)) ;; your code here ******** ) (add-compiler-defn 'block compile-block) (define (compile-triangle size direction) (display (list 'running 'compile-triangle)) ;; your code here ******** ) (add-compiler-defn 'triangle compile-triangle) (define (compile-pastey shape1 shape2 y-offset) (display (list 'running 'compile-pastey)) ;; your code here ******** ) (add-compiler-defn 'pastey compile-pastey) (define (compile-pastex shape1 shape2 x-offset) (display (list 'running 'compile-pastex)) ;; your code here ******** ) (add-compiler-defn 'pastex compile-pastex) (define (compile-reflectx shape x-center) (display (list 'running 'compile-reflectx)) ;; your code here ******** ) (add-compiler-defn 'reflectx compile-reflectx) (define (compile-reflecty shape y-center) (display (list 'running 'compile-reflecty)) ;; your code here ******** ) (add-compiler-defn 'reflecty compile-reflecty) ;;; ------------------------------------------------------------ ;;; ;;; printing shapes (define (print-shape shape max-x max-y) (display #\newline) ;; your code here ******** ) ;;; closure is a function representing a shape, e.g. the result of ;;; a call to compile. print the characters of this shape, from ;;; row 0 to max-y and column 0 to max-x (define (print-closure closure max-x max-y) (display #\newline) ;; your code here ******** )