First, "map" returns a lazy seq. Second, "do" only returns the result
of the last expression.

So, the mapping you do in your "do" form is never executed because you
never ask for the result.

Try wrapping the mapping in "dorun" to explicitly realize the lazy seq
from your mapping:

(defn foo []
 (do
   (dorun (map (fn [_] (throw (RuntimeException. "fail"))) [1 2]))
   "no exception"))

On Tue, Feb 17, 2009 at 5:11 PM, linh <nguyenlinh.m...@gmail.com> wrote:
>
> Hi,
> How come the following code does not throw an exception?
>
> (defn foo []
>  (do
>    (map (fn [_] (throw (RuntimeException. "fail"))) [1 2])
>    "no exception"))
>
> this however does throw exception:
>
> (defn foo []
>  (map (fn [_] (throw (RuntimeException. "fail"))) [1 2]))
>
> Is this a bug or am I missing something?
>
> >
>



-- 
Venlig hilsen / Kind regards,
Christian Vest Hansen.

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