Tim, I don't think your version of the signature supports variadic defaults well. Also, I'd (initially) implement fnil differently that Rich. Here's my fnil-2 that I *suspect* has the intended behavior
(defn fnil-2 [f & defaults] (fn[& args] (let [used-args (map (fn [default-value value] (if value value default-value)) defaults args)] (apply f used-args)))) user=>(def nil+ (fnil-2 + 0 1 2 3 4 5 6)) user=>(nil+ nil) 0 user=>(nil+ 0 nil) 1 user=>(nil+ 0 0 nil) 2 user=>(nil+ 0 0 0 nil) 3 ... user=>(nil+ 0 0 0 0 0 0 nil) 6 ;This example exceeds the provided # of nil values user=>(nil+ 0 0 0 0 0 0 0 nil) NPE You get the idea. Also, Rich's style matches the signature of partial better, which I personally prefer. Just my $.02 Sean On Jan 1, 6:45 pm, Timothy Pratley <timothyprat...@gmail.com> wrote: > On Dec 13, 1:24 am, Rich Hickey <richhic...@gmail.com> wrote: > > > fnil seems to me to have greater utility than patching all functions > > that apply functions with default-supplying arguments. > > Hi Rich, > > To further comment on fnil, after having experimented with it a bit > now, I've come to slightly prefer specifying the 'default' value > before the function just because I think it reads nicer: > (fnil 0 inc) ;; instead of (fnil inc 0) > (fnil [] conj) ;; instead of (fnil conj []) > I read it as "fill nil with 0 for inc" > I suppose "fill nil of inc with 0" makes just as much sense but I find > "inc 0" leads my eye to believe 0 will always be passed to inc, > whereas "0 inc" does not. Putting the function last makes it clearer > to me that the 0 is conditional. It also looks more like if nil 0. > This contrasts with get, which makes perfect sense having the default > last, but I think at this point fnil and get are sufficiently far > apart that a different argument order would not be surprising. > > Just a small observation I thought I'd raise for discussion to see > what preferences are out there if this function becomes widespread. > > Regards, > Tim. -- 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