[racket] returning self as sync result with struct prop:evt and wrap-evt

From: Neil Van Dyke (neil at neilvandyke.org)
Date: Wed Jun 27 18:20:45 EDT 2012

Matthew Flatt wrote at 06/27/2012 05:41 PM:
> At Wed, 27 Jun 2012 17:34:27 -0400, Neil Van Dyke wrote:
>> If I have a struct that wraps an input-port, and I want the struct to be
>> usable as an event that returns the struct as the sync result... is
>> there an better way than the code below?
> You can use a procedure that receives "self" as the `prop:evt' value.

Oops, I missed that part of the docs.  Thanks.

Question: If I put a "log-debug" into that "(lambda (self) ...)" proc, 
looks like the proc is applied every time i call "sync".  If the 
"log-debug" isn't in there, is the overhead of applying that proc and 
"wrap-evt" each time I call "sync" practically zero, or would I possibly 
get better I/O performance with the "letrec" and calling "wrap-evt" only 

(I'm thinking about when having "sync" called a gazillion times in tight 
inner loops for I/O-intensive stuff.  I realize that "sync" itself is 
probably a little more expensive than I like to pretend.)

Neil V.

Posted on the users mailing list.