<div dir="ltr">Luckily, you've asked the person who wrote that code!<div><br></div><div>There's a few things going on here...</div><div><br></div><div>1. read-request is just provided for backwards compatibility, the Web server itself ONLY use make-ext:read-request (as renamed to make-read-request on line 23); for instance, see <a href="https://github.com/plt/racket/blob/v5.3.4/collects/web-server/web-server.rkt#L62">https://github.com/plt/racket/blob/v5.3.4/collects/web-server/web-server.rkt#L62</a></div>
<div><br></div><div>The reason is that we want to give you the option to never use HTTP/1.1 and always close a connection and that is part of request handling.</div><div><br></div><div>That's the first part of make-ext:read-request, or rather why we have make-read-request at all.</div>
<div><br></div><div>2. Next, we want to make sure that whenever read-request throws an error, it kills the connection (which will in turn kill the Web server thread and free resources). However, we don't want to clutter the definition of make-read-request with these details, particularly because the test suite wants to turn this behavior off for various reasons and uses require/expose to get the /real/ make-read-request.</div>
<div><br></div><div>So, in all, I wouldn't call this a use of a 'pattern' but rather a weird hodge-podge of the stuff from the past decade of maintaining the Web server :)</div><div><br></div><div>Jay</div><div>
<br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Sep 10, 2013 at 7:28 PM, Chad A. <span dir="ltr"><<a href="mailto:chad@neomantic.com" target="_blank">chad@neomantic.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks for your help.  I was sure it would have something to do with<br>
capturing bindings in a closure, but the code in question seems to<br>
lack a closure.  Maybe I'm missing something, though.<br>
<br>
Here's the code:<br>
<a href="https://github.com/plt/racket/blob/v5.3.4/collects/web-server/http/request.rkt#L102" target="_blank">https://github.com/plt/racket/blob/v5.3.4/collects/web-server/http/request.rkt#L102</a>.<br>
<br>
Thanks again,<br>
Chad<br>
<br>
<br>
--<br>
Chad Albers<br>
<a href="http://www.neomantic.com" target="_blank">http://www.neomantic.com</a><br>
(pgp signature available on request)<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On Tue, Sep 10, 2013 at 10:16 PM, Jay McCarthy <<a href="mailto:jay.mccarthy@gmail.com">jay.mccarthy@gmail.com</a>> wrote:<br>
> I think more context would be useful to know why a specific case is useful.<br>
> But, I'll do my best with none...<br>
><br>
> By using functions like this, you can control when things happen and what<br>
> they can see. For instance...<br>
><br>
> (define (make-worker)<br>
>   (define a (build-list 10 add1)<br>
>   (define (worker)<br>
>     ;; a is visible to 'worker'<br>
>     (+ (first a) 10))<br>
>   worker)<br>
><br>
> ;; a is not visible here<br>
><br>
> ;; .... you do some other work ...<br>
><br>
> ;; and only now do you run the construction of a<br>
><br>
> (define some-worker<br>
>   (make-worker))<br>
><br>
> ;; .... you do some other work before getting the contents<br>
><br>
> (define answer<br>
>   (some-worker))<br>
><br>
> This is all because closures are a basic form of objects---their environment<br>
> values are their "private fields" and "apply" is their one method. Thus, any<br>
> time that you would find OO useful, you might find a pattern like this<br>
> useful. Especially when you don't want to go whole hog and use the<br>
> object/class system from racket/class<br>
><br>
> Jay<br>
><br>
><br>
><br>
><br>
> On Mon, Sep 9, 2013 at 8:24 PM, Chad A. <<a href="mailto:chad@neomantic.com">chad@neomantic.com</a>> wrote:<br>
>><br>
>> Hi,<br>
>><br>
>> I'm wondering if someone can help me understand a design-pattern that<br>
>> I have noticed in the Racket code base. (I'm teaching myself, so<br>
>> review other people's code alot).<br>
>><br>
>> I've seen this pattern..which is a bit contrived.<br>
>><br>
>> (define (say-hello)<br>
>>   (define (display-hello)<br>
>>      (display "hello")))<br>
>><br>
>> So this produces a producer, and to evaluate it I would need to write<br>
>> ((hello)) => "hello"<br>
>><br>
>> But then I see this...<br>
>><br>
>> (define say-hi (say-hello)).  When I evaluate (say-hello), I get<br>
>> "hello".  Obviously, the definition of "say-hi" contains the evaluated<br>
>> (say-hello) than returns the 'display-hello' procedure to be<br>
>> evaluated.<br>
>><br>
>> My question is...why would I want to write the code like this? 3<br>
>> definitions have been created which could easily be compressed into<br>
>> one.<br>
>><br>
>>  (I also see nothing in the code I'm looking at that appears to<br>
>> capture a binding via a closure).<br>
>><br>
>> Thanks in advance for any insights someone can share.<br>
>><br>
>> Chad<br>
>> ____________________<br>
>>   Racket Users list:<br>
>>   <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
><br>
><br>
><br>
><br>
> --<br>
> Jay McCarthy <<a href="mailto:jay@cs.byu.edu">jay@cs.byu.edu</a>><br>
> Assistant Professor / Brigham Young University<br>
> <a href="http://faculty.cs.byu.edu/~jay" target="_blank">http://faculty.cs.byu.edu/~jay</a><br>
><br>
> "The glory of God is Intelligence" - D&C 93<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Jay McCarthy <<a href="mailto:jay@cs.byu.edu" target="_blank">jay@cs.byu.edu</a>><br>Assistant Professor / Brigham Young University<br><a href="http://faculty.cs.byu.edu/~jay" target="_blank">http://faculty.cs.byu.edu/~jay</a><br>
<br>"The glory of God is Intelligence" - D&C 93
</div>