Have you taken a look at parameters? http://docs.racket-lang.org/guide/parameterize.html http://docs.racket-lang.org/reference/parameters.html
There is also a way to “link units at runtime”, conveniently called “units”. http://docs.racket-lang.org/guide/units.html?q=unites#%28tech._unit%29 http://docs.racket-lang.org/reference/mzlib_unit.html Of course, those probably aren’t quite what you’re looking for (they’re mostly for linking units of *code* together at runtime). The usual solution to the problem you describe is Racket’s parameters. > On Oct 13, 2015, at 4:36 PM, Nota Poin <notap...@gmail.com> wrote: > > How do you deal with long-term state that your programming logic depends on, > but is only available at run-time? A persistent connection to a database, or > an RPC server for instance, or a logged in user account. Do you use > parameters? Session objects? Just raw globals? Or something stranger? > > This might be a crazy idea (probably is) but what I tried doing is > initializing state as a local variable, then instead of passing it like an > object, passing methods that use it directly as functions. The idea is to > have something like a module, but whose code cannot fully compile until the > session has been established. > > so like, > (define (sess cb) > (let ((thing (make-session))) > (cb > (lambda (arg) > (+ thing 23 arg)) > (lambda () > (do-things-with thing))))) > (sess (lambda (foo bar) (foo) (if (bar) ...))) > > Keeping track of the order of these passed functions gets confusing though, > when you try to extend one session-aware module-thingy with another. Now you > have to write all the functions passed to the “base” wrapper in the extending > wrapper, and make sure they’re all in order, and nothing’s missing. Using > keywords for everything would fix that, but is there a more elegant way to do > it? There's little documentation I can find about linking units at run-time. > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.