On 2013-11-11 08:46, Rikki Cattermole wrote:
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.
Absolutely. One of my favorite examples is the database query:
auto person = Person.where(e => e.name == "John");
Which translates to the following SQL:
select * from person where name = 'John'
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.
That's quite similar one of the examples, I like to call it "property
shortcut":
http://wiki.dlang.org/DIP50#Attribute_macros
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.
Why not? There's quite a lot that is not specified in this DIP. Mostly
because I haven't decided/figured out how it should work exactly. Of
course, any help is always appreciated.
--
/Jacob Carlborg