On Tuesday, 15 March 2016 at 08:02:34 UTC, Jaocb Carlborg wrote:
On Tuesday, 15 March 2016 at 00:29:17 UTC, Stefan Koch wrote:
Hi,
I found myself in need of __trait that might be useful to
include.
something that would give me the parameters of a the body of
the lambda as string and the parmeters of a lambda as
AliasSequence.
e.g
foreach (p;__traits(lambda, (x,y) => x < y)) {
writeln(p);
}
would output
x
y
x < y
I am sure this is doable unfortunately I lack the insight into
DMD to implement this in a reasonable amount of time, and code
quality.
Thanks in advance!
Stefan
To get the parameters as as strings, I think this [1] will
allow you to that. To get the body as a string, that sounds
almost as AST macros :)
[1] https://github.com/D-Programming-Language/dmd/pull/5201
--
/Jacob Carlborg
Hi Jacob,
I've been thinking quite a bit about the next step in the
evolution of D's metaprogramming, and I thought that AST macros
are the best way forward, however since then I become convinced
that macros are a distraction from a much more powerful language
feature.
Firstly, macros are a kind of declarative preprocessor, in the
case of AST macros they process ASTs. Surely operating at AST
level is a significant improvement than plain text processing,
however macros by themselves are separate language that requires
a lot of additions to work. One of the biggest advantages of D is
you don't need to use a different language for CTFE. Furthermore
being purely declarative is very limiting, compared to how
powerful imperative CTFE is.
Next, macros may add new syntax to the language or change the
meaning of the existing syntax which would be a very disruptive
change to the language (even if it's made in a backwards
compatible way).
Instead I think that if we improve D's existing introspection
capabilities and expose the compiler as a library at
compile-time, we will have a much powerful system than any
potential macro system, for a fraction of the complexity.
These videos are what changed my mind:
1. https://www.youtube.com/watch?v=OHZwYYW9koI
2. https://www.youtube.com/watch?v=59lKAlb6cRg
(Jonathan Blow's programming language for games)