On Tue, Jan 20, 2009 at 10:54 PM, Hugh Winkler <hwink...@gmail.com> wrote:
> but why not make "safe" the default? i.e.  use "unsafe-binding"  if
> you know it's OK.

Not all seqs are finite. Also, Clojure skews toward lazy-by-default.

Once a function has run inside a `binding, I would assume that the
result it delivers is exactly what it means to deliver. And `map means
to deliver a lazy seq.

If `binding, however, decided to do something with that result before
returning, then I would consider that a side-effect of binding.

It would mean that I cannot use `binding that produce a lazy-seq
sources from some IO resource or any infinite seq. This "safe" would
probably either do too much work in the wrong thread or blow my heap.

>From the interaction bellow, I'd probably prefer the style of the 'h
function for this kind of situation:

user=> (def *num* 16)
#'user/*num*
user=> (defn f [] (map (fn [_] *num*) [1]))
#'user/f
user=> (defn g [] (map (constantly *num*) [1]))
#'user/g
user=> (defn h [n] (map (constantly n) [1]))
#'user/h
user=> (binding [*num* 1024] (f))
(16)
user=> (binding [*num* 1024] (g))
(1024)
user=> (binding [*num* 1024] (h *num*))
(1024)

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