<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<span style="font-size:13px;font-family:arial,sans-serif">I had exactly the same confusion back when I first tried it. Your</span><br style="font-size:13px;font-family:arial,sans-serif"><span style="font-size:13px;font-family:arial,sans-serif">example is really helpful. Could it be added to the docs for make-pipe</span><br style="font-size:13px;font-family:arial,sans-serif">
<span style="font-size:13px;font-family:arial,sans-serif">and/or g(un)zip-through-ports?</span></blockquote><div><br></div><div>Go for it. I think that's one of the few problems I tend to have with Racket's documentation is a lack of examples. Function signatures and descriptions are all well and good, but it's not always clear how to get to that point.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
1. I notice that with-gzip and with-gunzip are identical except for<br>
the function they call. You could parameterize that away: Replace both<br>
with a single `with-pipe` function that takes any xxx-through-ports<br>
style function (input-port? output-port? . -> . any) as an argument.<br>
[1]<br>
<br>
Because the bulk of the code is about using make-pipe with any such<br>
"converter" function; it doesn't care which. And this pattern of using<br>
make-pipe could easily apply to functions like<br>
transfer-{encoding|decoding}-through-ports and<br>
content-{encoding|decoding}-through-ports for working with HTTP, and<br>
other transforms. Even the identity function for this, `copy-ports`.<br></blockquote><div><br></div><div>Definitely. Primarily I didn't do it since I really only need <font face="courier new, monospace">with-gunzip</font> for my work, <font face="courier new, monospace">with-gzip</font> was mostly because it was easy to copy/paste. The input is always several orders of magnitude larger than the output, so less point in gzipping it. </div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
2. There's a lot of thunking going on. On the plus side, traditional<br>
things like with-input-from-file use thunks, so it's consistent with<br>
that. On the other other hand a macro could simplify that so users<br>
don't need to write (lambda () body...) or (thunk body...), they just<br>
write body... directly.<br></blockquote><div><br></div><div>Yup. And that's one of the uglier parts of the code with lots of rightward drift going on. You're right on why I did it though, I wanted it to fit in with the rest of my code. I tend to use with-* rather than opening and closing things myself. In my own code, I've already written exactly that macro though as a wrapper over <font face="courier new, monospace">with-g(un)zip</font>.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
[1]: Yeah, it's awkward that gzip-through-ports takes those 2 extra<br>
arguments for filename and time -- it's not just (input-port?<br>
output-port? . -> . any) like the general `make-pipe` wants. But you<br>
could pass either of the following to `make-pipe`:<br>
(lambda (in out) (gzip-through-ports in out #f 0))<br>
(curryr gzip-through-ports #f 0)</blockquote><div><br></div><div>I used <font face="courier new, monospace">#f</font> and <font face="courier new, monospace">(current-seconds)</font>, but fair point. <font face="courier new, monospace">curry</font> / <font face="courier new, monospace">curryr</font> are nice! Yet another set of things built into Racket that I'd never thought to look for--I would have used the lambda example.</div>
</div></div></div>