<div dir="ltr">I'm pretty sure code is collected in (regular) Racket. Small numbers aren't collected, true, but they also don't really take any space. Big numbers are collected, too. (I'm not sure about interned symbols.)<div>
<br></div><div>Robby</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Feb 14, 2013 at 7:26 AM, Jay McCarthy <span dir="ltr"><<a href="mailto:jay.mccarthy@gmail.com" target="_blank">jay.mccarthy@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In the Web server language, all anonymous functions are turned into<br>
top-level structures masquerading as functions where the fields are<br>
their free variables. For instance:<br>
<br>
(define (f x) (lambda (y) (+ x y))<br>
<br>
becomes, roughly,<br>
<br>
(struct a-lambda42 (x)<br>
#:property prop:procedure<br>
(lambda (the-structure y)<br>
(define x (a-lambda42-x the-structure))<br>
(+ x y)))<br>
(define (f x) (make-a-lambda42 x))<br>
<br>
In your program, the expression<br>
<div class="im"><br>
(web-cell-shadow wc-anonymous (λ (x) 'more-distinctive-text))<br>
<br>
</div>becomes<br>
<br>
(struct a-lambda43 () #:property prop:procedure (lambda (s x)<br>
'more-distinctive-text))<br>
(web-cell-shadow wc-anonymous (make-a-lambda43))<br>
<br>
Notice that the anonymous function has no fields because there are no<br>
free variables. The distinctive text is not shown anywhere in the URL<br>
because it is part of the code, not part of the data, of the closure.<br>
<br>
If you change the program slightly to<br>
<br>
(web-cell-shadow wc-anonymous<br>
(let () (define y 'more-distinctive-text)<br>
(λ (x) y)))<br>
<br>
then y is a free variable, so when you look at the URL:<br>
<br>
<a href="http://localhost:8000/;((%22c%22%20.%20%220((3)%204%20(((lib%20%5C%22web-server%2Flang%2Fabort-resume.rkt%5C%22)%20.%20%5C%22lifted.6%5C%22)%20((lib%20%5C%22web-server%2Flang%2Fweb-cells.rkt%5C%22)%20.%20deserialize-info:frame-v0)%20(%23%5C%22%2Ftmp%2Ft.rkt%5C%22%20.%20%5C%22lifted.1683%5C%22)%20(2%20.%20%5C%22lifted.1991%5C%22))%200%20()%20()%20(0%20(1%20(h%20-%20()%20(lifted.1485-0%20.%20this-is-a-song-about-Japan)%20(lifted.1521-1%202%20(b!%20.%20more-distinctive-text))))%20(c%20(v!%20(3)%20%23f%20%23f))))%22))" target="_blank">http://localhost:8000/;((%22c%22%20.%20%220((3)%204%20(((lib%20%5C%22web-server%2Flang%2Fabort-resume.rkt%5C%22)%20.%20%5C%22lifted.6%5C%22)%20((lib%20%5C%22web-server%2Flang%2Fweb-cells.rkt%5C%22)%20.%20deserialize-info:frame-v0)%20(%23%5C%22%2Ftmp%2Ft.rkt%5C%22%20.%20%5C%22lifted.1683%5C%22)%20(2%20.%20%5C%22lifted.1991%5C%22))%200%20()%20()%20(0%20(1%20(h%20-%20()%20(lifted.1485-0%20.%20this-is-a-song-about-Japan)%20(lifted.1521-1%202%20(b!%20.%20more-distinctive-text))))%20(c%20(v!%20(3)%20%23f%20%23f))))%22))</a><br>
<br>
You see the distinctive text.<br>
<br>
As far as GC goes, code is not generally collected in Racket anyways.<br>
Any data that is an intrinsic part of the program text (such as<br>
literal symbols and numbers) will always be around in your program<br>
whether you use #lang web-server or not.<br>
<br>
Jay<br>
<div><div class="h5"><br>
<br>
On Wed, Feb 13, 2013 at 8:34 PM, Galler <<a href="mailto:lzgaller@optonline.net">lzgaller@optonline.net</a>> wrote:<br>
> Good evening,<br>
><br>
> I've been investigating lang web-server, performance and garbage collection<br>
><br>
> I have a question regarding anonymous functions and web cells<br>
><br>
> Examples below require:<br>
><br>
> #lang web-server<br>
> (require racket/serialize<br>
> web-server/lang/web-cells)<br>
><br>
><br>
> Constants appear serializable by their value being explicitly written out<br>
><br>
><br>
> For example,<br>
><br>
> (serialize 'this-is-a-song-about-japan)<br>
><br>
> ;-> '((3) 0 () 0 () () this-is-a-song-about-japan)<br>
><br>
><br>
> Whereas anonymous functions appear serializable by the mechanism of being<br>
> "lifted" (i.e. reified) to a module level binding<br>
><br>
> For example<br>
><br>
> (serialize (λ (x) x))<br>
><br>
> ;-> '((3) 1 (('anonymous-module . "lifted.1386")) 0 () () (0))<br>
><br>
><br>
> Moving the discussion to web-cells<br>
><br>
> (define wc-constant (make-web-cell #f))<br>
><br>
> (define wc-anonymous (make-web-cell #f))<br>
><br>
><br>
> (web-cell-shadow wc-constant 'this-is-a-song-about-Japan)<br>
><br>
> (web-cell-shadow wc-anonymous (λ (x) x))<br>
><br>
> (printf " wc-constant: ~A\n wc-anonymous: ~A\n"<br>
> (serialize wc-1)<br>
> (serialize wc-2))<br>
><br>
> returns<br>
><br>
> wc-constant: ((3) 1 (((lib web-server/lang/web-cells.rkt) .<br>
> deserialize-info:primitive-wc-v0)) 0 () () (0 lifted.1534-0))<br>
><br>
> wc-anonymous: ((3) 1 (((lib web-server/lang/web-cells.rkt) .<br>
> deserialize-info:primitive-wc-v0)) 0 () () (0 lifted.1570-1))<br>
><br>
><br>
><br>
> While now both values are 'lifted' (i.e. reified), a close examination of<br>
> the URL-string sent back to a client after send/suspend/dispatch<br>
><br>
> reveals that, with respect to the constant, lifted.1534 appears to be<br>
> explicitly represented, elsewhere in the string as an associative pair i.e.<br>
> (lifted.1534 this-is-a-song-about-Japan)<br>
><br>
> whereas for the anonymous function, its not clear that its reference,<br>
> lifted.1570 is explicitly represented<br>
><br>
> Which leads me to wonder about whether the reference to the anonymous<br>
> function, lifted.1570, is being maintained on the server,<br>
><br>
> And if so, how is it being garbage collected, as its impossible to ever<br>
> determine that it is unreachable.<br>
><br>
> I will also point out that prior to a year ago, anonymous functions failed<br>
> the serializability predicate. (serializable? anon-func) -> #f. I can pull<br>
> out the correspondence/background related to that if desirable.<br>
><br>
> I apologize if I'm just misreading the data.<br>
><br>
> Here's the complete example,with a stateless web server. Note that when you<br>
> inspect the url-string**for the datum this-is-a-song-about-Japan, its there,<br>
> but when looking for the datum more-distinctive-text, its not present in the<br>
> url-string.<br>
><br>
> **right click on the link, then copy/paste, or click the 'click-me' link and<br>
> copy/paste the URL from the address bar)<br>
><br>
> Thanks very much.<br>
><br>
><br>
> Thanks again.<br>
><br>
><br>
><br>
> #lang web-server<br>
><br>
> (require web-server/servlet-env)<br>
><br>
> (define wc-constant (make-web-cell #f))<br>
><br>
> (define wc-anonymous (make-web-cell #f))<br>
><br>
><br>
> (web-cell-shadow wc-constant 'this-is-a-song-about-Japan)<br>
><br>
> (web-cell-shadow wc-anonymous (λ (x) 'more-distinctive-text))<br>
><br>
> (define (start request)<br>
> (letrec ((response-generator (λ (make-url)<br>
> (response/xexpr `(html (head)<br>
> (body (a ((href<br>
> ,(format "~A" (make-url receive-request)))) "click me"))))))<br>
> (receive-request (λ (request)<br>
> (response/xexpr `(html (head)<br>
> (body "Thank you. We<br>
> are done."))))))<br>
> (send/suspend/dispatch response-generator)))<br>
><br>
> (serve/servlet start<br>
> #:stateless? #t<br>
> #:launch-browser? #t<br>
> #:connection-close? #t<br>
> #:quit? #f<br>
> #:listen-ip #f<br>
> #:port 8000<br>
> #:servlet-path "/")<br>
><br>
><br>
><br>
> Thanks much.<br>
><br>
> Zack<br>
<br>
<br>
<br>
</div></div>--<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 class="HOEnZb"><div class="h5"><br>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</div></div></blockquote></div><br></div>