I see this old post by Fogus:
With this example:
(defn constrained–fn [f x]
{:pre [(pos? x)]
:post [(= % (* 2 x))]}
(f x))
But I see this modern example:
(defn func ^{:pre [(pos? x)]
:post [(< % 100) (> % 1)]}
[x]
(+ 1 x))
Where it is in the metadata.
But here I still the old style:
(defn constrained-sqr [x]
{:pre [(pos? x)]
:post [(> % 16), (< % 225)]}
(* x x))
I was away from Clojure for a few years, so I think it I missed some of its evolution. Is one of these styles favored?
I'm struggling with an issue where I cannot get the error to show up, even when I deliberately send in data that would cause the assertion to return false.
My function started:
(defn get-cisa-advisories
[cisa-advisory-urls]
{
:pre [(set? cisa-advisory-urls)]
:post [(vector? %)]
}
(println "get-cisa-advisories")
(try
When I called this with a vector, I got no error, but the app silently died. I'm confused about this. The call to this function is wrapped in a try/catch block, and that assertion must have thrown an error because that is where the app dies, yet I couldn't see the exception in my catch block.