Just for kicks, I wrote a terribly simple implementation of an OO system (with sub-type polymorphism).
Here's an example of it in use - http://s-expressions.com/2009/12/10/frumios-a-silly-object-system-for-clojure/ Obviously one wouldn't use it in a real production system (one would use multi-methods etc. instead), but it's fun to see that Clojure is powerful enough to implement something like this in ~70 lines of code. More importantly, it shows that if you use something like this OO system which gives you most of what Java/C++ gives you in terms of traditional OO, you're actually limiting yourself. Of course, you could expand this into a full blown CLOS-style object system.... On Dec 14, 9:45 am, lambdatronic <gwjoh...@uvm.edu> wrote: > Umm mbrodersen...I believe Laurent was merely pointing out that you > can accomplish everything you did with your macros with regular > functions. The functions are actually shorter and clearer to read > than the macros as well. That is a pretty clear abuse of macros. > > The only thing macros do here is prevent you having to prepend ' or : > to your value or method names. IMHO (and I suspect I'm not alone on > this one) that's actually going to make your code harder to understand > than otherwise. > > To demonstrate: > > YOURS > ===== > > (defmacro ? [object value] > "Get an object value - same as object.value; in C# but immutable" > `(get ~object (keyword (str '~value)))) > > (defmacro ! [object method & args] > "Call an object method - same as object.method(args); in C# but > immutable" > `((get ~object (keyword (str '~method))) ~object ~...@args)) > > (defmacro != [object name value] > "Set an object value - same as object.name = value; in C# but > immutable" > `(assoc ~object (keyword (str '~name)) ~value)) > > AS REGULAR FNs > ============== > > WITH QUOTED VALUES > ================== > (defn ? [object value] > "Get an object value - same as object.value; in C# but immutable" > (object (keyword (str value)))) > > (defn ! [object method & args] > "Call an object method - same as object.method(args); in C# but > immutable" > (apply (object (keyword (str method))) object args)) > > (defn != [object name value] > "Set an object value - same as object.name = value; in C# but > immutable" > (assoc object (keyword (str name)) value)) > > WITH KEYWORD VALUES > =================== > (defn ? [object value] > "Get an object value - same as object.value; in C# but immutable" > (object value)) > > (defn ! [object method & args] > "Call an object method - same as object.method(args); in C# but > immutable" > (apply (object method) object args)) > > (defn != [object name value] > "Set an object value - same as object.name = value; in C# but > immutable" > (assoc object name value)) > > And honestly, if you look at the keyword examples (the last 3 > functions), it's hard to justify why you would even want to define > these functions in the first place. > > 1. (? object value) is longer and less idiomatic than (object value). > > 2. (! object method arg1 arg2 ...) is hardly shorter than > (apply (object method) arg1 arg2 ...), and the second one is again > idiomatic clojure and therefore easier for everyone to understand. > > 3. (!= object name value) just aliases != for assoc. Again, not > idiomatic. > > So why exactly would you want to use these macros? > > END OF LINE -- 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 Note that posts from new members are moderated - please be patient with your first post. 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