On 09/16/2011 08:24 PM, Simen Kjaeraas wrote:
On Thu, 15 Sep 2011 19:14:24 +0200, Jonathan M Davis
<[email protected]> wrote:

On Thursday, September 15, 2011 03:41 bearophile wrote:
Christophe:
> > What is "unuseful and confusing" about:
> >
> > max!"a.length"(range); ?
>
> What is confusing is that I don't know if this function returns a
> length, or one of the elements of the range.

In Python the max and min work this way, and the students I have taught
Python don't see this as a problem. On the opposite, they are
thankful for
this feature.

> It seems
> (to me) more natural to give it a predicate to compare elements two
at a
> time. This is what is used in c++ std lib.

It's less natural. And D is not C++, there are more than just C++
programmers in D. And it leads to longer & more complex code.

I think that that's up for debate. I would fully expect a min/max
function to
be using a comparator function, which means using a binary predicate.

This seems weird to me. min already has a binary predicate - a < b.
This predicate is what defines min, any other predicate would make it
a different function - usually reduce, unless we're talking about
argMin (does argReduce make any kind of sense?).

That said, there are cases where a < b is not enough, owing to some
types not having a nice and simple comparison. Hence, binary
predicates should also be allowed. I just feel that in the general
case, binary predicates dilute the meaning of min/max. Would you
consider this code good?
min!"a > b"(range);
That's not min, that's max.

That is min. But of a different ordered set.

An ordered set is a pair of set and total order (a total order is a binary relation/binary predicate).

Assume ElementType!Range == int

then S=the set of range elements

What you call min is a least element/minimum of (S,SLT). This is
What you call max is a least element/minimum of (S,SGT)

Where SLT/SGT denote the relations typically used to compute the order of signed integers. But both are minima. You basically just cannot compute a maximum with min!binary_predicate. You can compute it's value by finding the minimum of the reverse ordered set. But it is impossible to compute the maximum directly.

More:
min!"a.member1 < b.member2"(range);
Again, it's not min, it's something else.


The same applies here. That IS min.

Reply via email to