[plt-scheme] Converting symbols to procedures?

From: Richard Cleis (rcleis at mac.com)
Date: Sun Aug 6 11:30:48 EDT 2006

At risk of totally misunderstanding what you mean
by `dispatching code,' I enclose the essence of
how one of my server programs dispatches code.
Expressions contained in strings are converted
to actual s-expressions, then kept in a list for
future evaluation (typically triggered by some
condition or event.)  Dealing with function names
by themselves seemed to require more work.

rac

;; Something needs to `dispatch' this function:
(define (server-function arg) arg)

;; ... but it needs to communicate with a string:
(define client-string "(server-function (random 30))")

;; the server can read the string into an expression:
(define server-expression (read (open-input-string client-string)))

;; Verification:
client-string
server-expression

;; The expression can be evaluated when needed:
(eval server-expression)
(eval server-expression)
(eval server-expression)

;Welcome to DrScheme, version 209.
;Language: Textual (MzScheme, includes R5RS).
;"(server-function (random 30))"
;(server-function (random 30))
;7
;12
;25
;>


On Aug 6, 2006, at 2:28 AM, Warren Henning wrote:

> Hi,
>
> I wanted to write some function dispatching code. I wanted to find a
> way to convert strings to procedure references, and of course there's
> string->symbol, but I can't find anything like symbol->procedure.
>
> Is there any way to convert from symbols to procedures?
>
> Thanks!
>
> Warren Henning
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.