DIP 50 - AST macros

Rikki Cattermole alphaglosined at gmail.com
Sun Nov 10 23:46:24 PST 2013


On Sunday, 10 November 2013 at 21:20:34 UTC, Jacob Carlborg wrote:
> I've been thinking quite long of how AST macros could look like 
> in D. I've been posting my vision of AST macros here in the 
> newsgroup a couple of times already. I've now been asked to 
> create a DIP out of it, so here it is:
>
> http://wiki.dlang.org/DIP50

One of our targets for AST macros should be the ability to 
replicate roughly linq from c# / .net.

An example syntax for use with AST could be:

auto data = [5, 7, 9];
int[] data2;
query {
  from value in data
  where value >= 6
  add to data2
}

Could be unwrapped to:

auto data = [5, 7, 9];
int[] data2;
foreach(value; data) {
  if (value >= 6) data2 ~= value;
}

This isn't a thought out design but it should at least be a 
target or a possibility.
Also c#'s get set should be rather similar as well.
Example:

getset {
  public int id;
  private bool exit;
}

Would translate to:

private int id;
private bool exit;
@property {
  void id(int v) {this.id = v;}
  void exit(bool v) { this.exit = v; }
  int id() { return this.id; }
  bool exit() { return this.exit; }
}

This would definitely open new possibilities up.
Disclaimer I don't like c# or .net but I am partial to these 
features.

At current point I think the DIP does have the necessary features 
to implement this. However it would be nice for safety to be able 
to get all scope variables of where the macro was initiated from. 
Being able to check for if a variable exists could provide much 
needed compile safety and better error messages.


More information about the Digitalmars-d mailing list