On Thu, Dec 9, 2010 at 10:50 PM, Alex Baranosky
<[email protected]> wrote:

>   (map (fn [dest] (dist-in-miles origin dest)) locations))

> It seems the stubbing is not happening when (distances "Boston,MA"
> "Albany,NY" "LosAngeles,CA") is being evaluated.  But if I put print
> statements in the function to see the value of dist-in-miles, it is clearly
> 2.0!

Perhaps you're being bitten by laziness. The value of dist-in-miles is
set to 2.0 for the duration of your test, then it reverts to something
else, *then* the (map ...) produced seq is being realized and using
the reverted value. If you put the print in "distances" it's printing
the 2.0 and then creating and returning the unrealized lazy seq, which
isn't realized until after the value reverts.

Laziness and temporary bindings mix like oil and water, unfortunately.

If you don't really need laziness, wrap a (doall ...) around the (map
...) in distances and see if that fixes it.

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

Reply via email to