Prevent top level forms from being lambda wrapped
In some circumstances, it's useful to prevent lamba-wrapping of forms, particularly at the top level. Some examples include macros that add import capability, like the paren6 import
macro. Another common one is top level forms that need to define symbols (like classes) which need to be accessible to other forms elsewhere in the file.
Is there a way to direct defpsmacro
to prevent lambda wrapping of generated code? I suspect there ought to be a way of binding in-function-scope?
to get the desired behavior.
To use the paren6 import macro as an example, given the following code:
(paren6:import (foo) "./myfile.js")
(foo)
Desired result:
var MODSTOR551 = require('./myfile.js');
var foo = MODSTOR551.foo;
foo();
Actual result
(function () {
var MODSTOR551 = require('./myfile.js');
var foo = MODSTOR551.foo;
})();
foo(); // Uncaught ReferenceError: foo is not defined
I submitted an issue to paren6, which appears to have been resolved with a bit of a hack, but I think Parenscript ought to provide a way for authors to avoid lambda wrapping through a standard mechanism.