From: Mark M. <mg...@ch...> - 2004-10-09 02:46:53
|
> A more appropriate way might be to use a macro: > > (define-macro (dynamicdefine name procedure) > `(set! ,(string->symbol name) ,procedure)) > > But this requires understanding quasiquote. This macro expands like > this: > >> (macroexpand '(dynamicdefine "bar" (lambda (x) (+ x 3)))) > (set! bar (lambda (x) (+ x 3))) Thanks! This strategy indeed does the job. > Why do you need such a factory? In the application I'm working on, jscheme is used to wrap many useful functions in order to create what is essentially a scripting language on top of the existing java code... however there are some sets of data which are loaded (and named) at run time that I'd like to be available in this scripting language. One of the keys to this scripting language is to hide the actual scheme syntax from the users, so when someone loads one of these data files the factory method will be called the generate a new function within scheme keyed to the name of that file. So yeah, that's the summary of how it will be used. :-) Thanks again! -mark |