How about doseq <http://clojuredocs.org/clojure_core/clojure.core/doseq> ?
Dňa utorok, 28. januára 2014 5:28:04 UTC+1 Mars0i napísal(-a): > > Back in 2007 ( > https://groups.google.com/forum/#!searchin/clojure/mapc/clojure/x0PDu_D6mP0/3A7CZe-ZDWAJ), > > Henk Boom raised the possibility of including in Clojure a function with > syntax like map, but semantics more like Common Lisp's mapc (or Scheme's > for-each, I believe). It works just like Clojure map, but applies the > function to items in a sequence (sequences) only for side-effects. A > sequence of results isn't generated, so there's no need for laziness. > There was discussion, and at one point Rich Hickey seemed to say that he > had added this kind of function, under the name 'scan'. It looks like scan > was subsequently renamed to 'dorun' (http://clojure.org/old_news), but > dorun doesn't do what mapc does. As far as I can tell, there is no such > function at present in Clojure. Is that correct? > > There are other ways to get the same functionality, and it's easy to > define a simple version of mapc (or whatever it should be called). > However, I like the map syntax, even for side-effects, and don't want to > reinvent the wheel. Even for small sequences, in which producing a > sequence as output isn't costly, using mapc tells readers of your code that > you're iterating over the list solely for side-effects. > > (defn mapc [f coll] (doseq [x coll] (f x))) > > For example, creating a mutable vector using core.matrix: > > => (def a (zero-vector :ndarray 5)) > #'popco.core.popco/a > => a > #<NDArray [0.0 0.0 0.0 0.0 0.0]> > => (mapc #(mset! a % -1) [0 2 4]) > nil > => a > #<NDArray [-1 0.0 -1 0.0 -1]> > > -- -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.