Skip to content

Instantly share code, notes, and snippets.

@pjstadig
Created October 11, 2014 17:55
Show Gist options
  • Save pjstadig/0b28ac50bf6319f877b4 to your computer and use it in GitHub Desktop.
Save pjstadig/0b28ac50bf6319f877b4 to your computer and use it in GitHub Desktop.
Clojure 1.7.0-alpha2
user=> (definline my-get [m k default] `(let [m# ~m k# ~k] (if (not (contains? m# k#)) ~default (get m# k#))))
#'user/my-get
user=> (my-get {:a :b} :a (throw (Exception. "foo")))
:b
user=> (my-get {:a :b} :not-found (throw (Exception. "foo")))
Exception foo user/eval20 (NO_SOURCE_FILE:3)
user=> (apply my-get [{:a :b} :a (throw (Exception. "foo"))])
Exception foo user/eval24 (NO_SOURCE_FILE:4)
user=> (apply my-get [{:a :b} :a :not-found])
:b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment