Thank you all for your replies
doseq rather than my loop is the ideal situation for me, looks a lot
nicer than my loop. I have to get used to avoiding loops when i can,
and not calling object methods functions!
thanks again everyone

On 15 Dez., 22:18, Laurent PETIT <laurent.pe...@gmail.com> wrote:
> Hello,
>
> so you have a mutating object. To mutate it you must call a method (please
> note, I don't use the term function, which has a different meaning than a
> class method, especially in clojure where functions are first class).
>
> You want a final call something like that:
> (mystery-fn-or-macro object method-to-call list-of-items)
>
> If you can afford in your situation of passing a real higher order function
> to mystery-fn-or-macro , like (fn [obj item] (.method-to-call obj item)),
> then mystery-fn-or-macro is simply based on doseq :
>
> (defn mystery-fn [object fn-calling-method list-of-items]
>   (doseq [item list-of-items] (fn-calling-method obj item)))
>
> and you call it as such :
> (mystery-fn object (fn [obj item] (.method-to-call obj item)) list-of-items)
>
> There's also the memfn macro in clojure.core for exactly this purpose:
> (mystery-fn object (memfn method-to-call item) list-of-items)
>
> But note that those days, memfn is somewhat deprecated in favor of raw (fn
> ...) or #(...) constructs.
>
> HTH,
>
> --
> Laurent
>
> 2009/12/15 tristan <tristan.k...@gmail.com>
>
>
>
> > 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<clojure%2bunsubscr...@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

Reply via email to