Open nmn opened 10 years ago
The Destructuring macros works great for variable decralations:
var [a,b] = someArray var {x,y} = someObject
It does this by doing the obvious thing, which is to store the array in a temporary variable first.
var _ref = someArray var a = _ref[0]; var b = _ref[1];
However, another great feature of destructuring is reassigning values that isn't supported by this macro as of now:
[a, b] = [b, a]
Now this should work basically the same way as everything else:
var _ref = [b, a] a = _ref[0]; b = _ref[1];
There may be a problem without a keyword, so it is possible to perhaps create an empty keyword that doesn't put var or let?
my best take so far is this:
let d = macro { rule { $id:ident } => { $id } rule { $pattern:destructor = $rhs:expr ;... } => { var __ref = $rhs; destruct $pattern ; __ref } } export d;
The Destructuring macros works great for variable decralations:
It does this by doing the obvious thing, which is to store the array in a temporary variable first.
However, another great feature of destructuring is reassigning values that isn't supported by this macro as of now:
Now this should work basically the same way as everything else:
There may be a problem without a keyword, so it is possible to perhaps create an empty keyword that doesn't put var or let?