Over here it was pointed out by @etardiff that \function
definitions don’t support nested definitions. I was more than a little taken back by that statement. Tonight I played around and sure enough, you can’t nest anything inside a function, it’s simply not supported.
I notice, even the docs skirt around the topic.
Note that the
\end
marker can optionally specify the name of the function to which it relates, enabling function definitions to be nested inside procedures, macros or widget definitions.
… but notable by its absence, not inside functions!
However, if the claim that…
The \function pragma is […] a shortcut syntax for the SetVariableWidget.
… is true, and, the SetVariableWidget supports nesting (it most certainly does), it begs the question, what happened during development that prevented \function
from supporting nesting?
The benefit of defining short, one-liners inside a function is obvious, especially when the function itself is tagged Macro or Global:
<!-- WRONG - DON'T DO THIS -->
\function .myfn(...)
\define x() ...
\define y() ...
[... <x> .... <y> ... ]
\end .myfn
<!-- THIS will work (sadly) -->
\define x() ...
\define y() ...
\function .myfn(...)
[... <x> .... <y> ... ]
\end .myfn
But now you’ve exposed <<x>>
and <<y>>
to the world (and stopped yourself from ever using the names anywhere else).
@jeremyruston Are we stuck with this anomaly or might things improve sometime in the future?
Thanks for reading.