proj4a - ; CS 61A project 4 part I solutions ; Problem A1...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
;;; CS 61A project 4 part I solutions ;;; Problem A1 make-line-obj (define-class (line-obj text) (method (next) (let ((result (car text))) (set! text (cdr text)) result)) (method (empty?) (null? text)) (method (put-back token) (set! text (cons token text))) ) (define (make-line-obj text) (instantiate line-obj text)) ;;; Problem A2 logo-type (define (logo-type val) (define (print-one val) (cond ((list? val) (display "[") (if (pair? val) (logo-type val)) (display "]")) (else (display val)))) (define (iter val) (print-one (car val)) (cond ((null? (cdr val)) '()) (else (display " ") (iter (cdr val))))) (cond ((null? val) '()) ((list? val) (iter val)) (else (print-one val))) '=no-value=) ;; The above is not the only possible solution, but any solution must ;; treat the top-level invocation differently from recursive calls in ;; order to avoid brackets around the outermost list. Points to note: ;; 1. This procedure is a Logo command, and so it must return =no-value= ;; like any other Logo command (as opposed to an operation). ;; 2. You may only invoke display on atoms; if you display a list it'll ;; be printed with parentheses instead of brackets. ;; 3.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

proj4a - ; CS 61A project 4 part I solutions ; Problem A1...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online