I ran into a problem in how architecture represents a certain part of my software. Suppose I have a function called make-temp-dir
(and many others) that does some dark magic depending on the current OS. I want implementations of these methods for each OS in a separate namespace.
Firstly, I believe that protocols (if possible) or multimethods are the solution to this. However, I have never seen an example of their use with implementations spanning multiple namespaces. And I canβt understand how this works out.
Secondly, if I use protocols for this, I will have to call the methods something like
(make-temp-dir current-os arg-1 arg-2)
Somehow, passing os as the first argument all the time doesn't look too good for me. For semantic sake, I would like make-temp-dir
to make-temp-dir
smart decisions depending on the OS. Of course, I can use some macros and do something like
(doto current-os (make-temp-dir arg-1 arg2))
but it seems wrong.
How to do it? Or am I going wrong? Any help was appreciated.
Change Ok, thanks a ton @kotarak, I managed to do something. For those who stumbled upon this, https://gist.github.com/2477120 . His work is beautiful, I think I will go with it. Thanks to everyone.
source share