Question

If I've defined a function with defn and a condition map containing :pre and :post forms, how can I retrieve that condition map? I notice that

(meta #'fn-name) 

doesn't contain the condition map. I'm specifically looking for the :pre conditions (in order to derive a predicate that's equivalent to them but doesn't assert). Is there any way to recover them other than walking the function body looking for asserts?

Was it helpful?

Solution

Unfortunately, they aren't stored anywhere after processing the fn macro. They're prepended/appended directly to the body of the function as asserts. You can check the relevant source lines in fn.

As a workaround, you could probably write your own variant of defn that grabs the :pre and :post conditions and stores them as metadata.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top