March 08, 2006
Walter Bright wrote:
> The implicit function template instantiation is a bit limited at the moment, deduction won't work for types derived from templates, and the mechanism to pick the most specialized template doesn't work.

Does the fact that implicit instantiation doesn't work when the template is a member of a class also belong to the 'limitation' category ? The error messages are quite misleading: "Foo.bar is not a declaration" and "template moduleName.Foo.bar(T) templates don't have properties" if Foo is a struct instead.


-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d-pu s+: a-->----- C+++$>++++ UL P+ L+ E--- W++ N++ o? K? w++ !O !M V? PS- PE- Y PGP t 5 X? R tv-- b DI- D+ G e>+++ h>++ !r !y
------END GEEK CODE BLOCK------

Tomasz Stachowiak  /+ a.k.a. h3r3tic +/
March 08, 2006
Jarrett Billingsley wrote:
> "Georg Wrede" <georg.wrede@nospam.org> wrote in message news:440E1336.3050608@nospam.org...
> 
>>BTW, what does "Implicit casts of non-bool to bool disallowed" mean?
> 
> It means you can no longer write
> 
> bool x = 5; 

Shhhhhttt! Good-bye C/C++ folks!

It's not like anybody would want to write exactly

    bool x = 5;

but more like

    bool x = strcmp("foo", "bar");
    if (!x) { /* do stuff */ }        // match
    else { /* call the cops! */ }     // no match

which, incidentally, is one of the more profound proposititions in any C-derived language.

The Old School Boolean C Logic was a perfectly functioning Concept. This fact _alone_ was the reason "Bool" took so long to be "formally" introduced into either C or C++. No regular programmer ever needed Prude Bool, only the Superior Theoreticians Thought it Wise to force this upon the language. It was profoundly useful as-is, and didn't need any pimping. A language that purports to be "to-the-metal" just has to take into consideration the fundamentals of [digital] life. And processor physics. (Wanna abstract away that? Then go to Java or whatever.)

The other night [in the D newsgroup, when it was getting hilarious] it dawned to me, that quite [too] many of the vocatious NG-members never had read their Boolean IT Fundamentals.

Good Grief: "there's just too many instances in history where the illiterati have dictated the outcome of otherwise intellectual confrontations". Damn!!

The ramifications of this (minor looking) modification are grave, I'm afraid.

Now what happens to

    if (stcmp("foo", "bar")) {}

???
March 08, 2006
Tom S wrote:
> Walter Bright wrote:
>> The implicit function template instantiation is a bit limited at the moment, deduction won't work for types derived from templates, and the mechanism to pick the most specialized template doesn't work.
> 
> Does the fact that implicit instantiation doesn't work when the template is a member of a class also belong to the 'limitation' category ? The error messages are quite misleading: "Foo.bar is not a declaration" and "template moduleName.Foo.bar(T) templates don't have properties" if Foo is a struct instead.

I think the feature is just mostly unfinished--I get get very simple cases to work, but that's it.  For example, in the code below, templA works just fine, but the slightly fancier templB is not accepted:

C:\code\d>type test.d
import std.c.stdio;

template templA( Type )
{
    void templA( Type val )
    {
        printf( "%.*s\n", typeid(Type).classinfo.name );
    }
}

template templB( Type )
{
    void templB( Type[] val1, Type val2 )
    {
        printf( "%.*s\n", typeid(Type).classinfo.name );
    }
}

void main()
{
    templA( "blah" );
    templB( "blah", 'b' );
}

C:\code\d>dmd test.d
test.d(22): template test.templB(Type) does not match any template declaration
test.d(22): template test.templB(Type) cannot deduce template function from argument types (char[4],char)

C:\code\d>
March 08, 2006
On Tue, 07 Mar 2006 19:47:38 -0500, Georg Wrede <georg.wrede@nospam.org> wrote:

> but more like
>
>      bool x = strcmp("foo", "bar");
>      if (!x) { /* do stuff */ }        // match
>      else { /* call the cops! */ }     // no match

You shouldn't even be doing that! You're inverting the meaning of true and false. Use int.

>
> Now what happens to
>
>      if (stcmp("foo", "bar")) {}

If this wasn't allowed I'd be furious.
March 08, 2006
Georg Wrede wrote:
> Jarrett Billingsley wrote:
>> "Georg Wrede" <georg.wrede@nospam.org> wrote in message news:440E1336.3050608@nospam.org...
>>
>>> BTW, what does "Implicit casts of non-bool to bool disallowed" mean?
>>
>> It means you can no longer write
>>
>> bool x = 5; 
> 
> Shhhhhttt! Good-bye C/C++ folks!
> 
> It's not like anybody would want to write exactly
> 
>     bool x = 5;
> 
> but more like
> 
>     bool x = strcmp("foo", "bar");
>     if (!x) { /* do stuff */ }        // match
>     else { /* call the cops! */ }     // no match
> 
> which, incidentally, is one of the more profound proposititions in any C-derived language.
> 
> The Old School Boolean C Logic was a perfectly functioning Concept. This fact _alone_ was the reason "Bool" took so long to be "formally" introduced into either C or C++. No regular programmer ever needed Prude Bool, only the Superior Theoreticians Thought it Wise to force this upon the language. It was profoundly useful as-is, and didn't need any pimping. A language that purports to be "to-the-metal" just has to take into consideration the fundamentals of [digital] life. And processor physics. (Wanna abstract away that? Then go to Java or whatever.)
> 
> The other night [in the D newsgroup, when it was getting hilarious] it dawned to me, that quite [too] many of the vocatious NG-members never had read their Boolean IT Fundamentals.
> 
> Good Grief: "there's just too many instances in history where the illiterati have dictated the outcome of otherwise intellectual confrontations". Damn!!
> 
> The ramifications of this (minor looking) modification are grave, I'm afraid.
> 
> Now what happens to
> 
>     if (stcmp("foo", "bar")) {}
> 
> ???

I suggest you read this : http://www.digitalmars.com/d/type.html before you make an ass of yourself. Oops, too late.
March 08, 2006
"Tom S" <h3r3tic@remove.mat.uni.torun.pl> wrote in message news:dul6ve$30gp$1@digitaldaemon.com...
> Does the fact that implicit instantiation doesn't work when the template is a member of a class also belong to the 'limitation' category ?

Yes.


March 08, 2006
Kyle Furlong wrote:
> Georg Wrede wrote:
> 
> I suggest you read this : http://www.digitalmars.com/d/type.html before you make an ass of yourself. Oops, too late.

Gee, you really must love me!

Ok, I'll check that out.
March 08, 2006
Ever heard that D supprts == on strings? =P

if( "foo" == "bar" )
{
	//code that never executes
}



Georg Wrede wrote:
> Jarrett Billingsley wrote:
> 
>> "Georg Wrede" <georg.wrede@nospam.org> wrote in message news:440E1336.3050608@nospam.org...
>>
>>> BTW, what does "Implicit casts of non-bool to bool disallowed" mean?
>>
>>
>> It means you can no longer write
>>
>> bool x = 5; 
> 
> 
> Shhhhhttt! Good-bye C/C++ folks!
> 
> It's not like anybody would want to write exactly
> 
>     bool x = 5;
> 
> but more like
> 
>     bool x = strcmp("foo", "bar");
>     if (!x) { /* do stuff */ }        // match
>     else { /* call the cops! */ }     // no match
> 
> which, incidentally, is one of the more profound proposititions in any C-derived language.
> 
> The Old School Boolean C Logic was a perfectly functioning Concept. This fact _alone_ was the reason "Bool" took so long to be "formally" introduced into either C or C++. No regular programmer ever needed Prude Bool, only the Superior Theoreticians Thought it Wise to force this upon the language. It was profoundly useful as-is, and didn't need any pimping. A language that purports to be "to-the-metal" just has to take into consideration the fundamentals of [digital] life. And processor physics. (Wanna abstract away that? Then go to Java or whatever.)
> 
> The other night [in the D newsgroup, when it was getting hilarious] it dawned to me, that quite [too] many of the vocatious NG-members never had read their Boolean IT Fundamentals.
> 
> Good Grief: "there's just too many instances in history where the illiterati have dictated the outcome of otherwise intellectual confrontations". Damn!!
> 
> The ramifications of this (minor looking) modification are grave, I'm afraid.
> 
> Now what happens to
> 
>     if (stcmp("foo", "bar")) {}
> 
> ???
March 08, 2006
Walter Bright wrote:
> Changed on_scope keywords per the general consensus of the n.g.
> 
> The implicit function template instantiation is a bit limited at the moment, deduction won't work for types derived from templates, and the mechanism to pick the most specialized template doesn't work.
> 
> http://www.digitalmars.com/d/changelog.html
> 
> 
Great stuff, Walter.
I hope you get 1.0 out before Google or IBM gets to you!

The scope stuff is very, very cool.

However, let me be a lone dissenter against the new if( auto = ) stuff.
My issue with it is what it may do to developers taking a peek at D.

C-Junkie: "Well there is my old reliable if statement...wait a minute...whats all this then?  This language is too weird, I am going back to my comfortable (language-X)."

This is yet another corner case bound to look small to experienced users but may shy away others from the language.

Again I vote for:

with( expression ) { ... } else { ... }

if expression is null then the else block is executed.

Of course, just my humble opinion.
-DavidM
March 08, 2006
On Wed, 08 Mar 2006 02:47:38 +0200, Georg Wrede wrote:

> Jarrett Billingsley wrote:
>> "Georg Wrede" <georg.wrede@nospam.org> wrote in message news:440E1336.3050608@nospam.org...
>> 
>>>BTW, what does "Implicit casts of non-bool to bool disallowed" mean?
>> 
>> It means you can no longer write
>> 
>> bool x = 5;
> 
> Shhhhhttt! Good-bye C/C++ folks!
> 
> It's not like anybody would want to write exactly
> 
>      bool x = 5;
> 
> but more like
> 
>      bool x = strcmp("foo", "bar");
>      if (!x) { /* do stuff */ }        // match
>      else { /* call the cops! */ }     // no match

Why would anyone in their right mind code something as stupid as that? This just misleads people who have to read your code. Instead do either ...

      bool x = cast(bool)strcmp("foo", "bar");
or
      int x = strcmp("foo", "bar");
or
      auto x = strcmp("foo", "bar");

In other words, code what you mean and mean what you code.

> which, incidentally, is one of the more profound proposititions in any C-derived language.

Profoundly dumb. <g>

> The Old School Boolean C Logic was a perfectly functioning Concept. This fact _alone_ was the reason "Bool" took so long to be "formally" introduced into either C or C++. No regular programmer ever needed Prude Bool, only the Superior Theoreticians Thought it Wise to force this upon the language. It was profoundly useful as-is, and didn't need any pimping.

Are you deliberately trolling?

I am a "regular programmer" and a correctly implemented boolean type is exactly what I need. What on Earth is "profoundly useful" about assigning a number to a boolean variable? It is far better (read: cost efficient at compile time, run time, and maintenance time) to code your intentions rather than taking advantage of a language's quirky 'features'. Such behaviour is only (IMNSHO) acceptable in absolutely runtime performance critical fragments, and then only if heavily and accurately documented.

> A language that purports to be "to-the-metal" just has to take into consideration the fundamentals of [digital] life. And processor physics. (Wanna abstract away that? Then go to Java or whatever.)

You seem to be confusing implementation with syntax/semantics. The compiler can do the semantic analysis correctly and then implement the code in the most efficient manner for the target platform. These are independent of each other.

> The other night [in the D newsgroup, when it was getting hilarious] it dawned to me, that quite [too] many of the vocatious NG-members never had read their Boolean IT Fundamentals.

And yet, you don't seem to "get it" either.

> Good Grief: "there's just too many instances in history where the illiterati have dictated the outcome of otherwise intellectual confrontations". Damn!!
> 
> The ramifications of this (minor looking) modification are grave, I'm afraid.
> 
> Now what happens to
> 
>      if (stcmp("foo", "bar")) {}
> 
> ???

This really shows that you are reading too much into the issue and not reading the specs themselves. In fact, a 2-minute test would answer this question for you anyway!

import std.stdio;
int Foo(int x)
{
   return x;
}

void main()
{

     bool x = cast(bool)Foo(0);
     if (!x) { writefln(" do stuff "); }
     else { writefln("call the cops!"); }

     if(Foo(2)) writefln("Foo(2)");
     if(Foo(0)) writefln("Foo(0)");

}

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocracy!"
8/03/2006 12:14:18 PM