On Jan 18, 2011, at 11:29 AM, Brian Marick wrote:
> f this were my problem, I'd wonder if I could make the computation accept
> functions. Then you could do something like this:
That was a lame solution except in the special case where the first element
must be computed. Here's a better solution, supposing that #'sprout-maker is
known to use #'next-sprout to compute its next result. It's awkward because of
a couple of not-yet-implemented features, which I'll explain after the code.
What the following code does is fake out #'next-sprout and ask Midje to
complain if it's ever called.
(defn ignore-return-value [x] nil)
(fact "sprouts are lazily created"
(expect (ignore-return-value (sprout-maker 3439393)) => anything
(not-called next-sprout)))
1. Midje goes to some effort to force evaluation of LazySeqs inside
the return value of the function-under-test. That's usually what you
want, so that faked functions do what you say they should.
The only way to prevent forcing, though, is by throwing away
the return value.
2. The normal "sweet" syntax doesn't support #'not-called, so I had
to use the "semi-sweet" syntax it's built on top of. There'll someday
be a better way to say that.
-----
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 [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en