Either I'm just too stupid, or D is lacking something
Wolfgang Draxinger
wdraxinger at darkstargames.de
Fri Jul 28 06:27:11 PDT 2006
Don Clugston wrote:
> To follow several other languages...
> identifier(str)
>
> creates an identifier called 'str', and is intended for dealing
> with keyword conflicts. If str was allowed to be a compile-time
> string literal, you could do practically *anything*. Easy
> enough to implement. BUT...
Hmm, what about this, somebody might come up with:
template Foo(T, char[] name)
{
sprintf(name, "foo_%s_1", name);
T identifier(name)(...){...};
}
I'd prefer to have string literals being treated by the compiler
not directly as char[]. Depending on the context it may be
treated like a char[] initializer or a lexical object.
Additionally it might be usefull to add some string manipulation
in the compiler, e.g. implementing the concatenation operator on
the lexical scope (if not done already).
template Foo(T, @name)
{
T @"foo_" ~ name ~ "_1"(...);
}
The '@' prefixing a template parameter would indicating, that it
must be a compile time fixed string literal (this could also
include const char[] literals on the module level). Within the
template the '@' indicates, that the following string, which
must be defined at compile time, is to be treated as a literal.
I understand, that it would make no large difference to implement
this in form of char[] template parameter, but I prefer a
different syntax to make it clear, that it means something
different.
> The problem is, it would be practically impossible for an IDE
> to deal with. (although, maybe that's true already).
Hmm, it wouldn't bee too complicated for an IDE to follow. D is
dread easy to parse compared to C or C++ (what the DMD frontend
proofes). An IDE using a D frontend would have no problems.
> LOL!
> D metaprogramming leaves C++ for dead.
I know, it one of the reasons why I completely dropped C++ as an
option for new projects by me.
> This is one of the few
> things that C++ can do (with a hack!) that D can't; but there
> are far more things that D can do, that C++ can't.
Actually I used this sort of stuff (C++ templates with C
preprocessor macro hacks) a lot of times to create boilerplate
code.
Of course D's metaprogramming is already way ahead of C++, but
the lack of ability to introduce new identifiers by
templates/mixins is an itching spot to me. Although C++ does not
even provide the abilities of mixins, the preprocessor allows to
hack it. - yes it's ugly, yes it's error prone, but it's there
and people make use of it.
Wolfgang Draxinger
--
E-Mail address works, Jabber: hexarith at jabber.org, ICQ: 134682867
GPG key FP: 2FC8 319E C7D7 1ADC 0408 65C6 05F5 A645 1FD3 BD3E
More information about the Digitalmars-d
mailing list