On Jan 18, 2011, at 6:16 AM, MiltondSilva wrote:

> Testing for laziness seems simple:
> (defn lazy? [coll]
>  (= (type coll) clojure.lang.LazySeq))

It's fairly easy to get other types that are (effectively) lazy. For example, 

        (cons 1 (map identity [1 2 3]))

is a clojure.Lang.Cons but I bet the original author would consider that just 
as good as a LazySeq.

> "For instance if you know a particular sequence could be particularly
> large or expensive in certain situations, you may want your tests to
> assert that it is not getting evaluated prematurely.."
> 
> That's what lazy seqs exists for. You get something that doesn't
> evaluated prematurely... Or am I missing your point?

I think the original author wants to have some computation that returns a 
sequential but be extra-special confident that elements have not yet been been 
evaluated. My hunch is that type-checking won't do it. For example, I expect 
he'd dislike it if his computation (or the functions it used) called #'doall 
somewhere. However, #'doall doesn't change the type:

    user> (type (doall (map identity [1 2 3])))
    clojure.lang.LazySeq

If this were my problem, I'd wonder if I could make the computation accept 
functions. Then you could do something like this:

    (fact "After the first, sprouts are not created until needed"
      (let [explosive-seed (fn [& rest] (throw (Error. "Boom!")))]
        (first (sprout-maker explosive-seed)) => identity-sprout?
        (second (sprout-maker explosive-seed)) => (throws Error #"Boom")))



-----
Brian Marick, Artisanal Labrador
Contract programming in Ruby and Clojure
Author of /Ring/ (forthcoming; sample: http://exampler.com/tmp/ring.pdf)
www.exampler.com, www.exampler.com/blog, www.twitter.com/marick

-- 
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