I’m facing a problem in how to architecture a particular piece of my software.
Lets say, I have a function called make-temp-dir (and many others) that does
some dark magic depending on the current OS. I want to be able to put the
implementations of these methods for each OS in a separate namespace.
Firstly, I believe protocols (if possible) or multimethods are the solution to
this. However, I’ve never seen an example of using these with implementations
spanning over multiple namespaces. And I’m not able to figure how this’d work
out.
Second, if I use protocols for this, I’ll have to call the methods something
like
(make-temp-dir current-os arg-1 arg-2)
Somehow, passing the os as the first argument all the time doesn’t look too good
to me. For semantic sake, I’d wish the make-temp-dir take intelligent
decisions depending on the OS. Sure I can use some macros and do something like
(doto current-os
(make-temp-dir arg-1 arg2))
but that feels wrong.
How should this be done? Or am I going the wrong way? Any help appreciated.
Edit: Okay, thanks a ton to @kotarak, I managed to get something working. For anyone that stumbles on this, https://gist.github.com/2477120. Its working fine, I think I’ll go with that. Thanks everyone.
In your startup code you have to initialize
current-oswithalter-var-rootbefore using any of the utility functions.Hope that gets you started.