2

Found some odd behavior in midje, not sure if it's midje related, or due to my misunderstanding of some clojure constructs, but it's puzzling:

Inside a facts statement, a for loop is not getting called:

(ns t1
  (:require [midje.sweet :refer :all ] )
  )

(facts
 (println "ok") ; -- this prints fine
 (for [val '(1 2 3)] (println val)) ; this does not

  (fact "junk"
        (> (.length "aaaaha") 3) => true ))

Thought maybe it had something to do with the for being overwritten in the ns but calling clojure.core/for behaves similarly.

Steve B.
  • 55,454
  • 12
  • 93
  • 132

1 Answers1

3

clojure.core/for "...yields a lazy sequence..."

You need to realize the sequence to see its side effects.

(doall (for [val '(1 2 3)] (println val)))

I'd suggest using something more appropriate like clojure.core/doseq:

(doseq [val '(1 2 3)] (println val))
Kyle
  • 21,978
  • 2
  • 60
  • 61