On 19.05.2009, at 23:44, maxsu wrote: > There, it's well defined and mathematical, and pretty neat; for > example, we can have a equality module where all we have to do is give > it a '<' function that knows how to compare a certain kind of data, > and and we get back shiny and correct >, <=, >=, and = functions.
That's possible in Clojure as well, see clojure.contrib.generic.comparison. The implementation is based on multimethods. > 2) The function just defines functions to the namespace it lives in, > which could probably be fixed by defining it differently. You could replace it by a macro creating the definitions in the current namespace. > I've been wondering about a similar problem, working with a little > gravity simulator for a system of particles, where I'd like to be able > to have the option of building a simulation where the particles have a > different representation, or where the gravity constant is different, > or a different integration scheme is substituted for the default. To > that end, I had been thinking of using a map to store the resulting > structure along with all its functions, but by the time I'd get to > writing all the functions to interface with that, I'd have created a > kind of light object system, and I don't know if that's the right > thing to do :). It's one option. If it turns out to work fine, you could abstract out the object system and make it available in the form of a library. There is nothing wrong about creating light-weight object systems. > I just thought of the idea of instantiating derived functions from > modular structures now, and I'm not actually sure that this will work > at run-time if it's done through a macro, so I'd like some feedback. What exactly do you have in mind? > And what do you guys think of storings fns in a map to achieve > structure modularity? That's perfectly fine with me. > Finally, is it possible to write functions that duplicate and modify a > namespace, returning a anonymous namespace which can be then imported > to the current scope, or passed elsewhere? Probably yes, minus the anonymous part (how would you access an anonymous namespace?). However, namespaces contain compiled functions in which all symbols have already been resolved, which is the problem that started this whole discussion. Copying a function from one namespace to another one won't make it use different global vars. Konrad. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---