[racket] About closing ports

From: Jack Firth (jackhfirth at gmail.com)
Date: Sun Aug 10 02:26:25 EDT 2014

Is there any particular reason there's no general close-port function that
works on both input ports and output ports? Would an implementation along
the lines of ((if (input-port? p) close-input-port close-output-port) p)
have problems that make this unreasonable? The only reason I ask is because
I was writing a macro let-ports that works like let (but only for ports)
that automatically closes the ports it defines. My naive implementations of
these are:

(define (close-port p)
  ((if (input-port? p) close-input-port close-output-port) p))

(define-syntax-rule (let-ports ([port port-expr] ...) body ...)
  (let ([port port-expr] ...)
    body ...
    (close-port port) ...))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140809/995655df/attachment.html>

Posted on the users mailing list.