In CommonLisp one can define local macros using MACROLET. Julia doesn’t have local macros, but one can imagine that a given global macro could provide local macros for use wwithin its body using a code walker and rules that re-write :macrocall
expressions.
Has anyone already implemented such a utility?
It seems straightforward enough, but I imagine there might be unforseen pitfalls.
What’s the problem I’m immediately trying to solve via local macros? I have a simple-minded expert system shell (Rete.jl) with an @rule
macro. That macro implements an install
method which will connect a new join node that implements the rule into a discrimination network. The body of a rule performs some conditionals and if all succeed then the rule will emit new facts to the network. Currently there are no diagnostics if a rule fails to make an expected conclusion if one of the conditionals fails because the join function just returns. I want there to be something (a local macro) that takes a predicate and logs when the predicate fails before the rule body exits.
This could be done with a closure but I want the log message to include the predicate expression and the source location.
I’m currently looking at both MacroTools and SymbolicUtils.
Any suggestions or insights?
Thanks.