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.