I just have to add that your code is really not idiomatic for Clojure. The do is not required here because there is an implicit do around the body of every fn (including one created with defn). Also, it's somewhat bad form to vertically align parentheses in Lisps. Finally, if you want to place sequence literals in your source code, we tend to prefer vectors to lists in Clojure since they semantically indicate that their contents are data (i.e. not a form to be evaluated for a function, special form, or macro result) and because they allow us to avoid unnecessary syntax quoting. An idiomatic form of your code would look like this:
(defn testdoseq [] (doseq [x ["a" "b" "c"]] (fn1 x)) (doseq [x ["1" "2" "3"]] (fn2 x))) Good luck, ~Gary On Jun 17, 2:39 pm, FD <fabien.dub...@scarlet.be> wrote: > Thanks > > I change the function with this one > > (defn testdoseq [] > (do > (doseq [x '("a" "b" "c")] > (fn1 x) > ) > (doseq [x '("1" "2" "3")] > (fn2 x) > ) > )) > > On 17 juin, 20:26, Aaron Cohen <aa...@assonance.org> wrote: > > > > > > > > > On Fri, Jun 17, 2011 at 2:13 PM, FD <fabien.dub...@scarlet.be> wrote: > > > Hello, > > > > What is wrong in this function? > > > > (defn testmap [] > > > (do > > > (map #(fn1 %) > > > '("a" "b" "c")) > > > (map #(fn2%) > > > '("1" "2" "3")) > > > )) > > > 1) "for" is lazy, its value is a LazySeq and the contents are only > > evaluated at need > > 2) The return value of "do" is the last statement executed > > 3) As a result, the resul of "testmap" is a LazySeq containing ("1" > > "2" "3"), the first LazySeq is discarded. > > 4) At the repl, the second LazySeq is printed because it's the result > > of calling testmap. As each entry is lazily realized, the println call > > prints "1" and the repl prints the return value of "println", which is > > nil. > > > > If fn1 = fn2 = println > > > the result is > > > (1 > > > 2 > > > nil 3 > > > nil nil) > > > > I expected this result > > > a > > > b > > > c > > > 1 > > > 2 > > > 3 > > > > Thanks > > > > -- > > > 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