Skip to content
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

One more important feature of destructuring. #21

Open
nmn opened this issue Aug 22, 2014 · 1 comment
Open

One more important feature of destructuring. #21

nmn opened this issue Aug 22, 2014 · 1 comment

Comments

@nmn
Copy link

nmn commented Aug 22, 2014

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?

@nmn
Copy link
Author

nmn commented Aug 22, 2014

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant