-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
do
does not retain scope
#106
Comments
I think you're right, wanna try to tackle this issue ? I can give some tips how to approach it. |
I can try to give it a try when I get a chance. Gonna have to find some time though, might take a few weeks (months?). |
So for me this (transpile) returns (function () {
list();
return list();
})(); Also trying (defmacro foo [a]
(do
(def b 1)
(do
(print a)
(print b)
(print *ns*)
())))
;=> void(0);
(print (foo :bar)) ;=> compiles to console.log(list());
(foo :bar) ;=> compiles to list(); Both print Imho, this makes perfect sense. Although there is no way to view the expression (the defmacro 'vaporizes' as a figure of speech) I can't show the expression (isn't there a macro-expand macro usually to serve this end?) but as a function I would assume it is just the same output only outside runtime context, during compile-time. Taking my macro as function to transpile, I get: var foo = exports.foo = function foo(a) {
return (function () {
var b = 1;
return (function () {
var b = 1;
console.log(a);
console.log(b);
console.log(_ns_);
return list();
})();
})();
}; Note the duplication of the |
If you used an arrow function from ES6, the problem would be solved. (do
(def foobar "foo")
(console.log foobar)) generates (() => {
var foobar = "foo";
return console.log(foobar);
})(); Of course this would end up meaning that the programs generated are then only compatible with environments that use ES6, so a fall-back mechanism should be supported if you wish to generate ES5 compliant code and get similar behavior. Arrow functions are more efficient than binding/calling a normal function for multiple reasons if they are available.
@robjens They aren't talking about lexical scopeing of variables here, they are talking about the context of |
The
do
form does not retain its parent scope, the way e.g.let
does.(do () ())
generates(function () { void 0; return (void 0); })()
, instead of(function () { void 0; return (void 0); }).call(this)
The text was updated successfully, but these errors were encountered: