This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ((eval (string->symbol "foo")) ...)



On Aug 7, 2007, at 10:44 AM, Boris Mizhen - èé wrote:


Hello List,

what is the right way (other than the one in subj) to call a function
if I have it's name as a string?

I don't think there's a standard way of doing this in Scheme, and that it is so for deliberate reasons. My understanding is that a Scheme compiler is allowed discard function names in its compiled output code; there's no guarantee that there will be any way of figuring out, at runtime, which function was called "foo" in the source code.


Also, I don't think there is a guarantee that the following code works in a compiled context:

(define (foo x) (+ 1 foo))
(eval '(foo 5))

For that code to work, eval must evaluate '(foo 5) in an environment that contains the binding of foo. I don't see anything in the R5RS spec that requires this to be the case:

http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-9.html# %25_sec_6.5

You can certainly put function's values in a hashtable indexed by strings or symbols; that's the sort of thing I'd do if I wanted to be able to dispatch to some function at runtime based on a string value.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]