bsl/printer.rkt
#lang racket

(require 2htdp/image)
(provide pyret-print)

(define (pyret-print v)
  (cond
    [(eof-object? v) (void)]
    [(void? v)
     (void)]
    [else
     (my-print-value v)
     (newline)]))


(define (my-print-value v)
  (cond
    [(image? v)
     (print v)]
    [(string? v)
     (write v)]
    [(number? v)
     (if (real? v)
         (display v)
         (let* ([rp (real-part v)]
                [ip (imag-part v)]
                [to-print
                  (if (> ip 0)
                      (format "~a+~aj" rp ip)
                      (format "~a~aj" rp ip))])
           (display to-print)))]
    [[list? v]
     (my-print-list v)]
    [(struct? v)
     (display (format "struct: ~a" (object-name v)))]
    [(procedure? v)
     (display "function")]
    [(equal? v #t) (display "True")]
    [(equal? v #f) (display "False")]
    [else 
     (error 'pyret-print "~e" v)
     (void)]))
  
(define (my-print-list lst)
  (cond
    ([null? lst]
     (display "[]"))
    [else
     (display "[")
     (my-print-value (first lst))
     (for-each (lambda (v)
                 (display ", ")
                 (my-print-value v))
               (rest lst))
     (display "]")]))