On 19.11.2013. 21:32, Jacob Carlborg wrote: > On 2013-11-19 19:32, luka8088 wrote: > >> Oh, I see. It seems that I indeed missed the point. >> >> It seems to me that this DIP could to be granulated into: AST >> reflection, AST manipulation and AST template. The reason for this, as >> far as I see, is that although they overlap in some cases, in other they >> could be used independently and it could help with understanding. >> >> Regarding AST reflection and AST manipulation, I have been thinking and >> found a few situations that bugs me: >> >> In the example of >> >> auto person = Person.where(e => e.name == "John"); >> >> what would be the response of: >> >> auto f = e => e.name == "John"; >> auto person = Person.where(f); >> >> I guess it should be a compiler error because f could be modified at >> runtime and f's body could be hidden. > > I haven't thought about that. But AST macros work at compile time
Well, do think about that :) auto f = e => e.name == "John"; if (true) f = e => e.name == "Jack"; auto person = Person.where(f); I can think of a many use cases where conditional query generation is required. But I don't see how this could be done using AST macros. > >> So basically AST macros are >> something that look like D but actually are not D. This seems to me like >> an example that look good as a toy example but fails on the larger scale >> so I agree with Water in this matter (unless better >> examples/explanations are provided). Or maybe I am not seeing it clear >> enough. >> >> But! Regarding AST templates, I think something like the following would >> be a great syntax sugar: >> >> int i = 5; >> >> Ast a = t{ // t as template >> int j = $i; >> int k = $i + $i; >> }; >> >> // ... alter ast here if necessary >> >> mixin(a); > > So you don't like that it's not a "mixin" there with AST macros? Um, sorry. I don't understand the question. This example (and suggestion) was suppose to show that we could allow AST mixins as well as string mixins. It should behave like string mixins but the main difference is that AST is structured so it much cleaner to manipulate. > >> Where syntax (and semantic) in template must be strictly D. The only >> difference would be $ sign which would allow reference to symbols >> outside the template. > > If the semantics need to be valid this is very limited. Even more > limiting than what we have now with string mixins. Note that with AST > macros, the input needs to syntactically valid. The resulting AST of the > macro needs to both be syntactically and semantically valid D code. > When I first started programing I was introduced to static typing. Then I discovered dynamic typing and dynamic structures (in php mostly). And for me at that time it was much better and easier to use. However, over time I learned that sometimes limitations are good and now like static typing much more :) My point here is that limits are sometimes good, although that don't seem that way. I think that we should think of a more complex (real world) examples and than real issues will reveal themselves.