[plt-scheme] The filename of the file in the definition window
At Wed, 19 Dec 2007 16:39:32 -0600, "Robby Findler" wrote:
> On Dec 19, 2007 4:15 PM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> > Avoid creating pipes, because it creates too much work for you in
> > managing a concurrent copy operation and closing the pipe at the right
> > time. Instead, parameterize the call to `system' to set
> > `current-input-port' to your port.
I was reacting in part to this thread:
http://list.cs.brown.edu/pipermail/plt-scheme/2007-December/021727.html
> I would have thought that something like
>
> (thread (lambda () (copy-port ...) (close-*-port ..)))
>
> would have been all you'd need.
Plus the `thread-wait's, which you have. You're relatively good at
this. :)
Also, it would be a good idea to wait until the process is done. If the
process explicitly closes its stdout and stderr before existing, and if
you create processes in a loop, it's possible (though unlikely) that
you'd create processes faster than they terminate.
Still, I think it's too much work in the sense that `system' will do
all of that for you, and it will do it more efficiently in some cases
(like this one, where the port is a file port). Just write
(define (run-wc-on-file filename)
(call-with-input-file filename
(λ (file-port)
(parameterize ([current-input-port file-port])
(system wc)))))
The first three lines are as in your code, the last two lines replace
another 16.
Matthew