[plt-scheme] Using eval in modules

From: John Clements (clements at brinckerhoff.org)
Date: Sat Jun 23 13:26:29 EDT 2007

On Jun 23, 2007, at 10:08 AM, Jean-Pierre Lozi wrote:

> Thanks for your answers,
> 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.
> 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 :
> (define (dispatch-message message)
>      ((let-values (((sender command args) (parse-message message)))
>         (let ((function (string->symbol
>                  (string-append "answer-"
>                                 (string-downcase command) "- 
> command"))))
>           ((eval function) sender command args)))))))
> 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.
> 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 :)

It appears to me that you can probably get something very much like  
what you want, using macros. BUT... I'll bet you thirty dollars it  
will take less time just to build a small 'cond' table.

Another question; is there a good reason that your messages are  
formatted as strings? Are they coming from the user?

John Clements

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2223 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20070623/1569285a/attachment.p7s>

Posted on the users mailing list.