<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; ">I don't believe your test case is relevant; evaluating an expression as the module is being loaded is not the same thing as evaluating an expression after the namespace is satisfied.  The following example might be closer to what you want.  In this case, eval-any-input is called from outside the module so that the argument can be returned for proof of concept.  However, you can write threads in the module that require no interaction from the requiring program.<DIV><BR class="khtml-block-placeholder"></DIV><DIV><DIV><DIV><DIV>(module simple-socket mzscheme</DIV><DIV>  (define  buffer (make-bytes 128))</DIV><DIV>  (define  udp-socket (udp-open-socket))</DIV><DIV>  </DIV><DIV>  (udp-bind! udp-socket "127.0.0.1" 12345)</DIV><DIV>  </DIV><DIV>  (define  (eval-any-input)</DIV><DIV>    (let-values</DIV><DIV>        (((n-rxed ip port)</DIV><DIV>          (udp-receive! udp-socket buffer)))</DIV><DIV>      (eval</DIV><DIV>       (read</DIV><DIV>        (open-input-string</DIV><DIV>         (substring (bytes-&gt;string/utf-8 buffer)</DIV><DIV>                    0</DIV><DIV>                    n-rxed))))))</DIV><DIV>  </DIV><DIV>  (define  (provided-f arg)</DIV><DIV>    arg)</DIV><DIV>  </DIV><DIV>  (provide eval-any-input</DIV><DIV>           provided-f))</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>(require simple-socket)</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>(let  ((the-socket  (udp-open-socket)))</DIV><DIV>  (udp-send-to the-socket</DIV><DIV>               "127.0.0.1"</DIV><DIV>               12345</DIV><DIV>               (string-&gt;bytes/utf-8 "(provided-f 'modulated-argument)"))</DIV><DIV>  (udp-close the-socket))</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>(eval-any-input)</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>rac</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR><DIV><DIV>On Jun 23, 2007, at 11:08 AM, Jean-Pierre Lozi wrote:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite">Thanks for your answers,<BR><BR>Actually, what I am trying to do is quite simple : at some point in my program, I get different messages (strings). I am trying to call the appropriate function depending on the message I received. <BR><BR>Of course I could dispatch the messages using cond - calling the right function for each message. But I thought it would look nicer using a function :<BR><BR>(define (dispatch-message message)<BR>     ((let-values (((sender command args) (parse-message message))) <BR>        (let ((function (string-&gt;symbol<BR>                 (string-append "answer-"<BR>                                (string-downcase command) "-command"))))<BR>          ((eval function) sender command args))))))) <BR><BR>Of course, using the hash-table approach is similar to the cond approach. Such a function could be unsafe, but I could test the message with member before calling eval, in order to be sure that the handling function exists. <BR><BR>From what you all said, I understand that it is impossible. Too bad. I guess I'll have to  choose the cond/hashtable approach or to avoid modules :)<BR><BR>Well, if you have other ideas...<BR><BR><DIV><SPAN class="gmail_quote"> On 6/23/07, <B class="gmail_sendername">Danny Yoo</B> &lt;<A href="mailto:dyoo@cs.wpi.edu">dyoo@cs.wpi.edu</A>&gt; wrote:</SPAN><BLOCKQUOTE class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> <BR><BR>On Sat, 23 Jun 2007, Jean-Pierre Lozi wrote:<BR><BR>&gt; This works because you are calling (eval-string-with-1 "abc") from<BR>&gt; outside the module - but it doesn't when the function is called from the <BR>&gt; inside the module. For instance :<BR>&gt;<BR>&gt; (module foo mzscheme<BR>&gt;  (define  (abc x)<BR>&gt;    (display "foo")<BR>&gt;    (newline))<BR>&gt;<BR>&gt;  (define  (eval-string-with-1 string)<BR> &gt;    ((eval (string-&gt;symbol string)) 1))<BR>&gt;<BR>&gt; (eval-string-with-1 "abc")<BR>&gt;<BR>&gt;  (provide eval-string-with-1<BR>&gt;           abc))<BR>&gt;<BR>&gt; (require foo)<BR>&gt;<BR>&gt; Doesn't work. And that's what I need to do :/ <BR><BR>Hello Jean-Pierre Lozi,<BR><BR>Question: do you really need the full power of eval?  What are you really<BR>trying to do?<BR><BR><BR>If you're trying to expose a few functions to the outside world for<BR>dynamic dispatch, then rather than eval, then would a simpler dispatch <BR>table approach work for you?<BR><BR>Here's what it might look like:<BR><BR>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<BR>(module foo mzscheme<BR>   (require (lib "etc.ss"))<BR><BR>   (define (abc x) <BR>     (display "foo")<BR>     (newline))<BR><BR>   (define registered-handlers (hash-table 'equal<BR>                                           ("abc" abc)))<BR>   (define (eval-string-with-1 string) <BR>     ((hash-table-get registered-handlers string) 1)))<BR>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<BR><BR>This requires no eval trickiness, and is much safer in terms of limiting<BR>what kind of mischief the caller can do.  If the user tries to eval <BR>something that's not in the dispatch table, we can reliably catch that<BR>kind of thing.<BR><BR>In contrast, the eval approach exposes the full power of the language,<BR>including all the primitives, so in your original approach, stuff like: <BR><BR>     (eval-string-with-1 "exit")<BR><BR>will kill the runtime.<BR></BLOCKQUOTE></DIV><BR><BR clear="all"><BR>-- <BR>Jean-Pierre Lozi<BR><A href="http://www.lozi.org">http://www.lozi.org</A><BR>mailto:<A href="mailto:jean-pierre@lozi.org"> jean-pierre@lozi.org</A><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_________________________________________________</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><SPAN class="Apple-converted-space">  </SPAN>For list-related administrative tasks:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><SPAN class="Apple-converted-space">  </SPAN><A href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</A></DIV> </BLOCKQUOTE></DIV><BR></DIV></DIV></DIV></DIV></DIV></BODY></HTML>