private: No


(define (closing? tag)
  (not (member tag html-void-elements)))

(define html-void-elements
  '(area base br col command embed hr img input keygen link meta param source track wbr))

(define (print-attr attr)
    (let ((key (car attr))
          (value (cadr attr)))
      (display " ")
      (display key)
      (display "=\"")
      (display value)
      (display "\"")))

(define (alist->html alist)
  (cond
    ((null? alist) (display ""))
    ((eq? '% (caar alist)) (for-each print-attr (cdar alist)))
    (else (display "error"))))

(define (content->html content)
  (if (null? content)
    (display "")
    (->html content)))

(define (what-is x)
        (cond
          ((symbol? x) 'tag)
          ((string? x) 'content)
          ((eq? '% (car x)) 'alist)
          (else 'content)))

(define (content? x)
    (eq? 'content (what-is x)))

(define (alist? x)
    (eq? 'alist (what-is x)))

(define (element->html element)
    (let ((tag (car element))
          (alist (filter alist? element))
          (content (filter content? element)))
      (display #\<)
      (display tag)
      (alist->html alist)
      (display #\>)
      (content->html content)
      (if (closing? tag)
          (begin
            (display #\<)
            (display #\/)
            (display tag)
            (display #\>))
          (display ""))))

(define (->html tree)
  (cond
    ((list? tree)
     (for-each (lambda (t)
                 (if (not (string? t))
                   (element->html t)
                   (content->html t)))
               tree))
    ((string? tree) (display tree))
    ((null? tree) (display ""))
    (else (display "error"))))