Thank you all for your answers :)
Ryan
On Tuesday, October 29, 2013 7:40:41 AM UTC+2, Mars0i wrote:
This is essentially the same as some of the other solutions, but more
succinct:
(or (get a-map :b) (println Oh no!))
--
--
You received this message because you are subscribed to the
Or a shorter variant of the sentinel approach:
(let [r (get a-map :b ::unfound)]
(if (= r ::unfound)
(my-foo)
r))
On Sun, Oct 27, 2013 at 2:57 PM, Cedric Greevey cgree...@gmail.com wrote:
(get a-map :b my-foo) will result in the function object itself being
returned if :b is not
... or the no-sentinel find-based approach:
(if-let [[_ v] (find a-map :b)]
v
(my-foo))
Cheers,
Dave
On Mon, Oct 28, 2013 at 9:08 AM, Alex Baranosky
alexander.barano...@gmail.com wrote:
Or a shorter variant of the sentinel approach:
(let [r (get a-map :b ::unfound)]
(if (= r
This is essentially the same as some of the other solutions, but more
succinct:
(or (get a-map :b) (println Oh no!))
--
--
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
Hello,
I am trying to understanding why is this happening:
(defn my-foo [] (println Why do I get printed?))
#'sandbox4724/my-foo
(get {:b 1} :b (my-foo))
Why do I get printed?
1
Shouldn't (my-foo) only be called in case the key isn't found? Why am I
seeing the above behavior
The function's arguments will be evaluated before calling it.
So the (my-foo) will be called before 'get'.
2013/10/28 Ryan arekand...@gmail.com
Hello,
I am trying to understanding why is this happening:
(defn my-foo [] (println Why do I get printed?))
#'sandbox4724/my-foo
(get {:b 1}
You are getting my-foo evaluated, remove the parens around it.
Luc P.
Hello,
I am trying to understanding why is this happening:
(defn my-foo [] (println Why do I get printed?))
#'sandbox4724/my-foo
(get {:b 1} :b (my-foo))
Why do I get printed?
1
Shouldn't (my-foo)
Silly me, thank you for your replies guys!
One more question though, what if my-foo had parameters?
Ryan
On Sunday, October 27, 2013 6:55:34 PM UTC+2, Luc wrote:
You are getting my-foo evaluated, remove the parens around it.
Luc P.
Hello,
I am trying to understanding why is this
(get a-map :b my-foo) will result in the function object itself being
returned if :b is not found. If you want it to be called only in the event
of not found, you need either
(if (contains? a-map :b) (a-map :b) (my-foo)) -- which may perform the
lookup twice -- or
(if-let [r (a-map :b)] r