Whilst you solved your problem, you didn't get an answer about metadata.

There are multiple places metadata can appear in a function definition:

dev=> (defn ^{:one true} func (^{:two true} [x] {:three true} x) {:four 
true})
#'dev/func
dev=> (meta #'func)
{:one true, :arglists ([x]), :four true, :line 1, :column 1, :file 
"/home/seanc/.clojure/dev.clj", :name func, :ns 
#object[clojure.lang.Namespace 0x17b6ad97 "dev"]}
dev=> (->> #'func (meta) :arglists (mapv meta))
[{:two true, :three true}]
dev=>

I've delineated the arity of the function with ( ) for clarity so you can 
which metadata belongs to the function Var and which belongs to a specific 
arity, and you can see they are combined.

I've never seen anything except :pre/:post in position three and I've never 
seen :pre/:post in position two (until I saw your example from ostash.dev) 
-- but as you can see they are equivalent (and they combine).

I don't think I've ever seen function Var metadata in position four.
On Thursday, February 3, 2022 at 10:56:59 AM UTC-8 Laws wrote:

>
> 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/3cc16f33-3f7b-49dd-96e8-b20fdb37e9cdn%40googlegroups.com.

Reply via email to