From: Ken A. <kan...@bb...> - 2004-10-08 21:51:51
|
I'm not exactly sure what you want, but there are several ways to do this. The first is to use a procedure that uses some JScheme internals: (define (dynamicdefine name procedure) (jscheme.JS.setGlobalValue name procedure)) Example: > (dynamicdefine "bar" (lambda (x) (+ x 3))) #null > (describe bar) Closure named ?? (lambda (x) (+ x '3)) #t 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))) Why do you need such a factory? At 02:03 PM 10/8/2004 -0400, Mark McGettrick wrote: >Hey >I'm new to JScheme however I've quickly discovered my need to do a relatively complex thing... I'd like to be able to pass a string into a function which will then act as a factory to create a new function who's name is equal to the value of the input string. In other words: > >foo is set equal to "bar" >dynamicdefine (my function) with foo as a parameter should return a new function (whatever that may be) assigned to the name "bar" >now there would be a new function called: bar > >I guess this all comes down to: is there a way to cause the value of a string to be used as the name of a new symbol? >Perhaps I'm not even asking the question correctly... >Help? > >Thanks, >-mark > > > >------------------------------------------------------- >This SF.net email is sponsored by: IT Product Guide on ITManagersJournal >Use IT products in your business? Tell us what you think of them. Give us >Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more >http://productguide.itmanagersjournal.com/guidepromo.tmpl >_______________________________________________ >Jscheme-user mailing list >Jsc...@li... >https://lists.sourceforge.net/lists/listinfo/jscheme-user |