I see this old post by Fogus:

http://blog.fogus.me/2009/12/21/clojures-pre-and-post/

With this example:

(defn constrained–fn [f x]
  {:pre  [(pos? x)]
   :post [(= % (* 2 x))]}
  (f x))

But I see this modern example:

https://ostash.dev/posts/2021-07-01-pre-post-conditions/

(defn func ^{:pre [(pos? x)] :post [(< % 100) (> % 1)]} [x] (+ 1 x))

Where it is in the metadata. 

But here I still the old style:

https://clojure.org/reference/special_forms

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

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/e8d2b2da-592e-48ac-93e1-ab54ca54d9cdn%40googlegroups.com.

Reply via email to