February 08, 2007
Derek Parnell wrote:
> class Foo { . . . }
> class Bar { . . . }
> 
> Foo f = new Foo;
> Foo g = new Foo;
> Bar b = new Bar;
> 
> if (ordered( f,b,g ) ) ...
> 
> BANG! The template doesn't know about Foo and Bar, so there is no match. In
> fact, just getting a template for built-in types requires a few thousand
> combinations of a,b,c signatures and aliases to make it palatable.
> 
> That is why I thought mixin-expressions might be more useful in this case -
> working at the textual level rather than the template-matching level. But I
> do know how to do it.

It's really simple:

bool ordered(T, U, V)(T a, U b, V c)
{
  return a < b && b < c;
}

Expanding this to multiple arguments is also quite simple, but left as an exercise. :o)


Andrei
February 08, 2007
Andrei Alexandrescu (See Website For Email) wrote:
> Obligatory comment: it would return true also if it were interpreted as (a < b) == (c < d) or as ((a < b) == c) < d. So the example is unclear.
> 
> :o)
> 
> 
> Andrei

For ultimate clarity, I refer you to the Python language reference on the topic:

http://docs.python.org/ref/comparisons.html

It's probably better to point you there than for me to attempt to explain it poorly. :-)

-- 
Kirk McDonald
Pyd: Wrapping Python with D
http://pyd.dsource.org
February 08, 2007
On Wed, 07 Feb 2007 17:06:07 -0800, "Andrei Alexandrescu (See Website For Email)" <SeeWebsiteForEmail@erdani.org> wrote:

>Walter Bright wrote:

>> Andrei has proposed (and I agreed) that this should be done away with in the language, i.e. comparison operators should no longer be associative.

>For the record, (clears throat) let me add that I initially suggested to make them associative with the right meaning, but was shot down. Making the comparison operators (and that includes != and ==) nonassociative is the next best thing to do.

Agreed, but with an extra note - once the operators have been nonassociative for a while, maybe making them associative again (but with the right meanings) might be more palatable.

-- 
Remove 'wants' and 'nospam' from e-mail.
February 08, 2007
Kirk McDonald wrote:
> Andrei Alexandrescu (See Website For Email) wrote:
>> Obligatory comment: it would return true also if it were interpreted as (a < b) == (c < d) or as ((a < b) == c) < d. So the example is unclear.
>>
>> :o)
>>
>>
>> Andrei
> 
> For ultimate clarity, I refer you to the Python language reference on the topic:
> 
> http://docs.python.org/ref/comparisons.html
> 
> It's probably better to point you there than for me to attempt to explain it poorly. :-)

Oh, I did run the interpreter (gotta love Linux - all the cool stuff is one command away) and figured how chained comparisons work. Thanks a lot for the reference.

BTW, Perl 6 is slated to implement chain comparisons as well:

http://en.wikipedia.org/wiki/Perl_6#Chained_comparisons


Andrei
February 08, 2007
On Wed, 07 Feb 2007 19:51:06 -0800, Andrei Alexandrescu (See Website For
Email) wrote:


> It's really simple:
> 
> bool ordered(T, U, V)(T a, U b, V c)
> {
>    return a < b && b < c;
> }

Thanks. It wasn't clear to me in the docs how this would be achieved. I've
read the template docs many times and it still doesn't make much clear.

> Expanding this to multiple arguments is also quite simple, but left as an exercise. :o)

Okay, I'll give it a go, but I'm not confident.

I'd have a go at updating the docs but *Doc* changes are even harder to get accepted than phobos changes <G>

Walter, would it be too hard to make the documentation source available too? I'm not talking about the embedded phobos docs but all the other stuff. e.g. The source that generates the "template.html".


-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Justice for David Hicks!"
8/02/2007 4:29:42 PM
February 08, 2007
Derek Parnell wrote:
> On Wed, 07 Feb 2007 19:51:06 -0800, Andrei Alexandrescu (See Website For
> Email) wrote:
> 
> 
>> It's really simple:
>>
>> bool ordered(T, U, V)(T a, U b, V c)
>> {
>>    return a < b && b < c;
>> }
> 
> Thanks. It wasn't clear to me in the docs how this would be achieved. I've
> read the template docs many times and it still doesn't make much clear.

A tutorial for template code would indeed be great. A lil bird told me the mythical "The D Programming Language" book will definitely include one :o).

Andrei
February 08, 2007
Derek Parnell wrote:
> Walter, would it be too hard to make the documentation source available
> too? I'm not talking about the embedded phobos docs but all the other
> stuff. e.g. The source that generates the "template.html".

It's already up there!

http://ftp.digitalmars.com/doc.zip
February 08, 2007
On Wed, 07 Feb 2007 22:12:50 -0800, Walter Bright wrote:

> Derek Parnell wrote:
>> Walter, would it be too hard to make the documentation source available too? I'm not talking about the embedded phobos docs but all the other stuff. e.g. The source that generates the "template.html".
> 
> It's already up there!

And I assume that this fact is documented somewhere obvious. I'm not in the habit of browsing FTP sites on the off chance that something useful might be there. Also, if I had have seen "doc.zip" I would have assumed it was the distributed documentation and not the documentation source. Plus "doc.zip" doesn't exactly yell out "D PROGRAMMING LANGUAGE" either.

> http://ftp.digitalmars.com/doc.zip

Hmmm... your server doesn't think it is.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Justice for David Hicks!"
8/02/2007 5:17:21 PM
February 08, 2007
Derek Parnell wrote:
>> http://ftp.digitalmars.com/doc.zip
> 
> Hmmm... your server doesn't think it is. 

It was in the wrong directory... try again.
February 08, 2007
Walter Bright wrote:
> Right now, in D (as well as C and C++), when you see the expression:
> 
>     if (a < b < c)
> 
> what is your first thought? Mine is that it was written by a newbie who didn't realize that (a < b) returns true or false, and that it does NOT mean ((a < b) && (b < c)). 

So your first thought, the newbie's first thought and my first thought all agree: it means a<b && b<c

As was pointed out already, let's make it that way. Adding these chained comparisons improves readability* and adds another popular feature from scripting languages.

L.

* compare with: if (a < b && c > b)