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>&nbsp;&nbsp;&nbsp;&nbsp; ((let-values (((sender command args) (parse-message message)))
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (let ((function (string-&gt;symbol<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (string-append &quot;answer-&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (string-downcase command) &quot;-command&quot;))))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((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&#39;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 &quot;abc&quot;) from<br>&gt; outside the module - but it doesn&#39;t when the function is called from the
<br>&gt; inside the module. For instance :<br>&gt;<br>&gt; (module foo mzscheme<br>&gt;&nbsp;&nbsp;(define&nbsp;&nbsp;(abc x)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;(display &quot;foo&quot;)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;(newline))<br>&gt;<br>&gt;&nbsp;&nbsp;(define&nbsp;&nbsp;(eval-string-with-1 string)<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;((eval (string-&gt;symbol string)) 1))<br>&gt;<br>&gt; (eval-string-with-1 &quot;abc&quot;)<br>&gt;<br>&gt;&nbsp;&nbsp;(provide eval-string-with-1<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; abc))<br>&gt;<br>&gt; (require foo)<br>&gt;<br>&gt; Doesn&#39;t work. And that&#39;s what I need to do :/
<br><br>Hello Jean-Pierre Lozi,<br><br>Question: do you really need the full power of eval?&nbsp;&nbsp;What are you really<br>trying to do?<br><br><br>If you&#39;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&#39;s what it might look like:<br><br>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<br>(module foo mzscheme<br>&nbsp;&nbsp; (require (lib &quot;etc.ss&quot;))<br><br>&nbsp;&nbsp; (define (abc x)
<br>&nbsp;&nbsp;&nbsp;&nbsp; (display &quot;foo&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp; (newline))<br><br>&nbsp;&nbsp; (define registered-handlers (hash-table &#39;equal<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (&quot;abc&quot; abc)))<br>&nbsp;&nbsp; (define (eval-string-with-1 string)
<br>&nbsp;&nbsp;&nbsp;&nbsp; ((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.&nbsp;&nbsp;If the user tries to eval
<br>something that&#39;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>&nbsp;&nbsp;&nbsp;&nbsp; (eval-string-with-1 &quot;exit&quot;)<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>