BnMcGn / paren6

ES6 macros for Parenscript
Apache License 2.0
29 stars 0 forks source link

export and import don't work unless they are wrapped inside a lambda #2

Open aneilbaboo opened 4 years ago

aneilbaboo commented 4 years ago

Parenscript wraps top-level expressions in an evaluated anonymous function, so imported symbols can't be accessed. E.g.,

(paren6:import (foo) "./myfile.js")
(foo)

becomes

(function () {
    var MODSTOR551 = require('./myfile.js');
    var foo = MODSTOR551.foo;
})();
foo();
BnMcGn commented 4 years ago

Hi Aneil,

There's a fix for import in the latest commit. It's a bit hackish. Let me know if it works for you.

I'll take a look at export.

aneilbaboo commented 4 years ago

Cool, thanks, Ben - Just FYI. I'm working on a PR for Parenscript to allow turning off the automatic isolation of top-level forms. I'll post a link here when I'm ready.

BnMcGn commented 4 years ago

Sounds interesting. Please do post a link.

Export looks like it should be working as is. Let me know if you see any further problems.

aneilbaboo commented 4 years ago

Hi Ben - I made a bit of progress, but decided I'd be better off switching to Clojurescript.

Here's what I discovered: there's a unexported dynamic variable in-function-scope? that is used to prevent lambda-wrapping inside lambda and defun. However, it's not possible to set this within the ps macro body as it is evaluated before in-function-scope? is consulted. It also isn't possible to use the in-function-scope? behavior on all macros because this would change the behavior of parenscript for a lot of other system macros, which would almost certainly create problems. So, (I think) the only way to get this working properly inside parenscript is to add a mechanism to mark some macros as unwrappable.

I think I'll cross post this issue to the Parenscript repo. It's such a basic problem. Maybe they have an alternate solution to it.

aneilbaboo commented 4 years ago

I created an issue over in the Parenscript repo: https://gitlab.common-lisp.net/parenscript/parenscript/-/issues/9