I'm just learning lisp but wouldn't a macro be overkill? ; manually add each item (doseq [item items] (.add obj item))
; or wrapped in a function (defn add-all [obj items] (doseq [item items] (.add obj item))) (add-all obj items) If your java object had an addAll method that accepted a collection, then you probably could do: (.addAll obj items) I'm wondering why you want it to be a macro? Allen On Tue, Dec 15, 2009 at 12:31 PM, tristan <tristan.k...@gmail.com> wrote: > Hi guys, > > I have a list (which i don't know the size of) and i want to do > something like this: > (doto (MutatingJavaObject.) (.add (first list-items)) (.add (second > list-items)) ..... (.add (last list-items))) > > Now I may be doing this the complete wrong way, so if you have a > better solution please tell me. but i've been trying to build a macro > to expand this out, given the object, the function to call and the > list of items. > > i've been playing with various things, and manage to get a few things > that work if i pass the list of items in without being a list (i.e. (1 > 1 1) rather than '(1 1 1) or (list 1 1 1)) for example (defmacro d2 > [obj func inputs] (concat (list 'doto obj) (map #(list func %) > inputs))) but if i try and pass in my list-items variable it just > complains that it "Don't know how to create ISeq from: > clojure.lang.Symbol". > > perhaps i'm not fully grasping the concept of macros? i'm very new to > lisp and FP in general. > > while writing this email i had a light switch on that i could simply > do it like this: > (let [obj (MutatingJavaObject.)] > (loop [in list-items] > (when (not (empty? in)) > (.add obj (first in)) > (recur (rest in)))) > obj) > but i would still like to know if there is a way i could get the macro > i wanted going. > > please help! my googling and trauling through Stuart Halloway's book > have come up naught. > > thanks in advance! > -Tristan > > -- > 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 -- 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