<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Mar 17, 2009, at 1:25 PM, Thomas Chust wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>2009/3/17 Jeff de Vries &lt;<a href="mailto:jdevries@pfrog.com">jdevries@pfrog.com</a>&gt;:<br><blockquote type="cite">I'm trying to create a macro that creates a set of global function<br></blockquote><blockquote type="cite">definitions where those functions share some common state. &nbsp;Basically, the<br></blockquote><blockquote type="cite">intent is something like the following:<br></blockquote><blockquote type="cite">;;; doesn't work, creates local definitions instead of global ones<br></blockquote><blockquote type="cite">(let ((state (create-common-state)))<br></blockquote><blockquote type="cite"> &nbsp;(define (foo x) (use-common-state-one-way x state))<br></blockquote><blockquote type="cite"> &nbsp;(define (bar x) (use-common-state-another-way x state)))<br></blockquote><blockquote type="cite">[...]<br></blockquote><br>you could let your macro expand into a define-values form that looks like this:<br><br> &nbsp;(define-values (foo bar)<br> &nbsp;&nbsp;&nbsp;(let ([state (create-common-state)])<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(values<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(lambda (x) (use-common-state-one-way x state))<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(lambda (x) (use-common-state-another-way x state)))))<br></div></blockquote></div><br><div>Yes, that's what I was looking for. &nbsp;Short, sweet, easy to understand, and does exactly what I wanted.</div><div><br></div><div>Regarding some of the other comments:</div><div><br></div><div>The original was "clunky" in the sense that it first created the global names (initially set to null), and then went back and set the values in another pass. &nbsp;It was also not very clean if the create-common-state function blew up; in the original the global names are defined first, so if create-common-state blows up, those names are left hanging around. &nbsp;The define-values approach gets around that issue, in that if create-common-state blows up, nothing gets defined.</div><div><br></div><div>The other suggestions basically create a global gensym'd name for the common-state. &nbsp;But I really don't want these common-state objects polluting the global namespace, since they really don't need to. &nbsp;Again, the define-values approach does what I want.</div><div><br></div><div>Thanks for all the comments and suggestions!</div><div>Jeff</div><div><br></div></body></html>