I’ve just discovered the interesting fact that macros can be called
before they are declared, while trying to load the Chicago Full Note
with Bibliography:
http://www.zotero.org/styles/chicago-fullnote-bibliography (search
for the “issued” macro)
This complicates things slightly, and I’ve started reworking a small
portion of citeproc-js to cope with it. But in the midst of the work,
it has occurred to me that it’s probably risky design to permit this
in the first place.
If the engine expects macros to be declared before they are called, a
style that puts things in the wrong sequence can be stopped with an
error that says “CSL parsing error: call to undeclared macro. Macros
must be declared before they are called. Please check the sequence of
macro definitions in the style file.”. The operator can then fix
things up by rearranging the macro blocks.
On the other hand, if the engine permits one macro be invoked within
another before the first is declared, circular calls are possible.
That will be caught either by a low-level loop limitation in the
platform running the engine (in Rhino, I think this would cough up a
Java error trace), or by the consumption of all available memory in
the machine running the processor. The error message in the former
case will provide a wealth of irrelevant information, and is unlikely
to point at the actual (quite simple) problem. The latter, of course
(speaking as a lawyer) could turn out have costly and embarrassing
side effects.
Unless circular calls can be easily caught by a validator, adopting a
simple requirement that macros be declared before they are invoked in
the style (either directly or via another macro) seems like it would
be a friendly policy in the long run.
(This is an area where my lack of formal CS training might show
through; if there are use cases that would be blocked by this, I’ll
stand corrected. But on the face of it, it doesn’t look as though
anything would be lost.)
My 2 cents, anyway.
Frank