So what should I do? would using fmap helps? I have used let initially, but I moved away to make it as close as possible to my repl code/.
On Sunday, December 2, 2012 8:31:55 PM UTC-5, Sean Corfield wrote: > > Part of it is laziness: map is lazy so it doesn't do anything unless you > use the result. In the REPL, you print the result so map runs across the > whole sequence. In the function, only the last expression (draggables) is > returned so it is the only thing fully evaluated. > > Your code is very procedural tho'... you should not have 'def' anywhere > except the top-level (since it always creates top-level definitions - > globals). You probably want 'let' for local definitions. Since you want > non-lazy behavior, you're not going to want 'for' or 'map' - look at > 'doseq' instead. > > Hope that helps? > > > On Sun, Dec 2, 2012 at 5:25 PM, Arash Bizhan zadeh > <[email protected]<javascript:> > > wrote: > >> I am playing with clojurescript, and I have this code: >> >> (defn prepare [number] >> (def targets (take 4 (drop (* 4 (- number 1)) (dom/getElementsByClass >> "place-div")))) >> (def target-objects (map #(make-target %) targets)) >> (for [drag draggables target target-objects] >> (.addTarget drag target)) >> (map #(.init %) draggables) >> (map #(.init %) target-objects) >> draggables) >> >> It basically creates a bunch of dragNdrop objects. >> This code doesn't work in this method - no error, just doesn't do the job >> - >> but if I execute the lines one at a time from repl, it works fine. >> Can someone please explain what the heck is going on ? >> >> much appreciated. >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to [email protected]<javascript:> >> Note that posts from new members are moderated - please be patient with >> your first post. >> To unsubscribe from this group, send email to >> [email protected] <javascript:> >> For more options, visit this group at >> http://groups.google.com/group/clojure?hl=en > > > > > -- > Sean A Corfield -- (904) 302-SEAN > An Architect's View -- http://corfield.org/ > World Singles, LLC. -- http://worldsingles.com/ > > "Perfection is the enemy of the good." > -- Gustave Flaubert, French realist novelist (1821-1880) > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en
