Proposal: static template(fail)

BCS ao at pathlink.com
Mon Dec 17 10:53:49 PST 2007


Reply to Bruce,

> On Fri, 14 Dec 2007 20:01:17 -0000, BCS <ao at pathlink.com> wrote:
> 
>> Reply to Bruce,
>> 
>>> On Fri, 14 Dec 2007 19:09:25 -0000, BCS <ao at pathlink.com> wrote:
>>> 
>>>> what would this do?:
>>>> template Foo(T)
>>>> {
>>>> static if(logic1!(T)) template(fail);
>>>> }
>>>> template Foo(T)
>>>> {
>>>> static if(logic2!(T)) template(fail);
>>>> }
>>>> from a programers level, it might be valid. My though is (an wow
>>>> could  this be costly) try all cases*, if there isn't exactly one
>>>> match, error.
>>>> * Walter's not going to like that for performance reasons.
>>> I'm not so sure about that. Its a bit like saying he wouldn't like
>>> you
>>> to
>>> write poorly designed / optimised code. He may not like it but a
>>> programming
>>> language can't help but permit it even if it does discourage it.
>> I'm taking about DMD's performance. The compile time cost of find a
>> template match could go through the roof with the "backtracking finds
>> one match" solution.
>> 
> Prolog is entirely based on backtracking huge numbers of predicates
> and it doesn't run that slowly. I don't think it would be much of a 
> problem in D unless you write a huge number of really complex evil
> templates and stick them all in one module.
> I'm not sure even the legendary obfuscator Downs could stretch it to
> breaking point.
> Mr. Blade library might come closer. Anyway, as with any language
> feature you should only pay for it if you use it. Unless you are
> overusing it, it shouldn't be a problem.

take a look at scrapple.backmath, the bulk of it is a huge list of static 
ifs inside templates. The way it's set up now it doesn't do any backtracking, 
but I rather dislike the brut force approach it is taking ("is this xyzzy? 
No? how about xyzzY? No? How about...[next 100 lines skipped]") The way code 
seems to go, new stuff will get layered on top of old stuff. Add backtracking 
into the mix as part of the language and soon D will get a rep of "yah it's 
good, but I can wright, debug, compile and be done faster in C than I can 
compile in D".





More information about the Digitalmars-d mailing list