> I sort of remember Rich Hickey say this, but I am not sure :).
I was a bit mistaken.
In this video (
http://blip.tv/clojure/clojure-data-structures-part-2-714064 ) , around
42nd minute, he says that assoc is "the normal way" and is "more
convenient" because you can assoc multiple keys and val
> 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 co
I sort of remember Rich Hickey say this, but I am not sure :).
As far as I see it, it is generally better to use more specific functions,
as they make the assumptions about the types of the arguments more
explicit. Sometimes they are also more efficient (but probably not in this
case).
So, for
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 {}
Hi,
Am 29.08.2012 um 23:38 schrieb dmirylenka:
> Although, code working with maps shouldn't use conj anyway.
Why?
Kind regards
Meikel
signature.asc
Description: Message signed with OpenPGP using GPGMail
Hm.. There seem to be cases when nil is not equivalent to {} when working
with maps:
(conj {} [:a :b]); => {:a :b}
(conj nil [:a :b]); => ([:a :b])
Although, code working with maps shouldn't use conj anyway.
Any other examples?
On Wednesday, August 29, 2012 9:08:07 PM UTC+2, dmirylenka wrote:
On Aug 29, 2012, at 12:18 PM, Brian Marick wrote:
> Why does `(merge)` return nil? I would have expected it to return the unit
> ({})
I agree with your intuition -- I expected an empty map. However, the doc says
"Returns a map that consists of the rest of the maps conj-ed onto the first"
wh
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}
etc.
On Wednesday, August 29, 2012 7:36:26 PM UTC+2, Moritz Ulrich wrote:
>
> This isn't true in Clojure: http://clojure.org/lisps
>
> However,
On Wed, Aug 29, 2012 at 9:41 AM, Joop Kiefte wrote:
> An empty sequence is equal to nil.
How so?
user> (some #(= % nil) ['() [] {}])
nil
--
Ben Wolfson
"Human kind has used its intelligence to vary the flavour of drinks,
which may be sweet, aromatic, fermented or spirit-based. ... Family
and s
This isn't true in Clojure: http://clojure.org/lisps
However, most functions treat an empty seq as nil because they call `seq'
on their arguments.
On Wed, Aug 29, 2012 at 6:41 PM, Joop Kiefte wrote:
> An empty sequence is equal to nil.
>
> 2012/8/29 Ambrose Bonnaire-Sergeant :
> > My guess is t
On Thu, Aug 30, 2012 at 12:41 AM, Joop Kiefte wrote:
> An empty sequence is equal to nil.
>
What do you mean?
=> (seq? ())
true
=> (= nil ())
false
>
> 2012/8/29 Ambrose Bonnaire-Sergeant :
> > My guess is that `merge` has an invariant "if all args are nil, return
> nil",
> > making calls to
An empty sequence is equal to nil.
2012/8/29 Ambrose Bonnaire-Sergeant :
> My guess is that `merge` has an invariant "if all args are nil, return nil",
> making calls to `seq` "contagious" from args to return value.
>
> => (merge (seq {}) (seq {}))
> nil
>
> Just a guess though.
>
> Thanks,
> Ambr
My guess is that `merge` has an invariant "if all args are nil, return nil",
making calls to `seq` "contagious" from args to return value.
=> (merge (seq {}) (seq {}))
nil
Just a guess though.
Thanks,
Ambrose
On Thu, Aug 30, 2012 at 12:18 AM, Brian Marick wrote:
> Why does `(merge)` return ni
Don't know why nil is returned instead of {}, but
> (+) => 0
> (*) => 1
following that line of reasoning:
> (merge nil {:a 1})
{:a 1}
> (merge {} {:a 1})
{:a 1}
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to cl
14 matches
Mail list logo