> It's not a unit if you're using `if-let` and expect nil to represent 
failure and {} to represent a success that establishes no bindings. 

You mean, something like this, right? :

(if-let [{:keys [a]} {}] "Hi"); => "Hi"

(if-let [{:keys [a]} nil] "Hi"); => nil

Interesting example!

In my own code, however, I wouldn't use a collection (in this case, a map) 
as a test expression inside if (which happens here under the hood).
Exactly because in many cases empty sequence is equivalent to nil.
Instead, I would explicitly test for emptiness: (if (seq my-map) this that).

On Thursday, August 30, 2012 12:46:05 AM UTC+2, Brian Marick wrote:
>
>
> On Aug 29, 2012, at 2:08 PM, dmirylenka wrote: 
>
> > I would say, they treat nil as an empty sequence, which makes nil, 
> effectively, a unit: 
> > 
> > (assoc nil :a :b) ; => {:a :b} 
> > (merge nil {:a :b}) ; => {:a :b} 
>
> It's not a unit if you're using `if-let` and expect nil to represent 
> failure and {} to represent a success that establishes no bindings. 
>
> ----- 
> Brian Marick, Artisanal Labrador 
> Contract programming in Ruby and Clojure 
> Occasional consulting on Agile 
>
>
>

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

Reply via email to