IDE shows undefined for function name created by macro

For the purposes of my DSL, I want to allow rules to be defined which take no parameters. So I have written a macro which basically looks like defn, except you don’t need to put an empty vector for the parameters, because there never will be any. The macro is -

(defmacro rule
“a business rule”
[name & statements]
`(defn ~name


This works, but the annoying thing is that in any editor/IDE I have used (Cursive, VS Code with Calva) the name of the new rule is highlighted as undefined. I can fix this by modifying my macro to take a symbol instead, but this just introduces a little bit more complexity.

Is there a way of making this name not show up as an error ?
Obviously it doesn’t happen when you use defn - but is this something that is built in ?

EDIT - one potential solution: I could just use def in conjunction with a modified version of the rule macro which uses fn instead of defn,
eg, (def MyRule (rule …))

Cursive has support for analysing macros in the same way as something else that it already knows about. Take a look at the “Macro Support” documentation.

Looking at the Calva documentation they just use clj-kondo, which means you should be able to do something similar with the :lint-as configuration setting in your project’s .clj-kondo/config.edn file.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.