(define (close-port p) (cond ((input-output-port? p) (close-input-port (close-output-port p))) ((input-port? p) (close-input-port p)) ((output-port? p) (close-output-port p)) (else (throw "Not a port" p))))