On Tue, Jan 18, 2011 at 12:22 AM, Nick Brown <nwbr...@gmail.com> wrote: > Hi, I'm wondering if there is a good way to test if a given sequence > is lazy, and if so, how much of it has been evaluated. I know the > fact that it is lazy should be transparent, but I'm thinking in the > context of unit testing knowing that could be valuable. 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. > > I suppose I could hack the generator function to cause a side effect > that I could test for, but is there an easier way?
I've got some code that changes the way the REPL prints lazy seqs so that it never forces the realization of anything. It prints anything that's already been forced, but then prints "...unrealized..." for the rest. I don't know if this is useful for unit testing, but I've found it helpful at the REPL. Also note that it's a complete hack -- includes big chunks of code copied from clojure.core (hence the copyright notice), makes use of internal clojure details that could change at any time, probably fails in various spectacular ways. Use at your own risk. :-) http://gist.github.com/589694 --Chouser http://joyofclojure.com/ -- 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