Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I wrote this with-input-from-pipe function for Guile. I’m not that comfortable with dynamic-wind or set-current-input-port, so I’d appreciate any critiques.

(use-modules (ice-9 popen)
             (srfi srfi-26))

(define (with-input-from-pipe command thunk)
  (let ((old (current-input-port))
        (pipe (open-input-pipe command)))
    (dynamic-wind
      (cute set-current-input-port pipe)
      thunk
      (lambda ()
        (set-current-input-port old)
        (close-pipe pipe)))))
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.