March 14, 2013
On Thursday, 14 March 2013 at 18:41:25 UTC, bearophile wrote:
> Andrea Fontana:
>
>> I always think X < Y return a single bool,
>
> Having a practice with NumPy and the like, I think X < Y as returning as many bools as the length of X and Y:
>
>>>> from numpy import *
>>>> a = array([1, 5, 1])
>>>> b = array([1, 1, 5])
>>>> a < b
> array([False, False,  True], dtype=bool)
>
>
> Programmers with experience of Matlab, Matcad, etc, feel the same.
>
> Bye,
> bearophile

But does sort!"a<b" still work if it returns an array?

It doesn't make sense for me :) if you ask me if a int vector is
lesser than another one I don't mean every single component but
the whole vector. Same goes for strings or any other range.
March 14, 2013
Andrea Fontana:

> But does sort!"a<b" still work if it returns an array?

See the difference in syntax:

a < b
a[] < b[]

Bye,
bearophile
March 15, 2013
Am Thu, 14 Mar 2013 22:15:11 +0100
schrieb "bearophile" <bearophileHUGS@lycos.com>:

> Andrea Fontana:
> 
> > But does sort!"a<b" still work if it returns an array?
> 
> See the difference in syntax:
> 
> a < b
> a[] < b[]
> 
> Bye,
> bearophile

This is "just" a syntax ambiguity. a[] takes the complete slice of the array 'a'. And a dynamic array in D is a slice. So if you use a or a[] in an expression doesn't make much of a difference.

-- 
Marco

March 15, 2013
Marco Leise:

> This is "just" a syntax ambiguity. a[] takes the complete
> slice of the array 'a'. And a dynamic array in D is a slice.
> So if you use a or a[] in an expression doesn't make much of a
> difference.

Yet in D the only accepted syntax to perform a vector op sum is to use add square brackets both operands:


void main() {
    auto a = new int[5];
    auto b = new int[5];
    auto c = new int[5];
    c[] = a[] + b[]; // OK
    c[] = a + b; // Error: invalid array operation
    c[] = a[] + b; // Error: invalid array operation
    c[] = a + b[]; // Error: invalid array operation
}


Bye,
bearophile
1 2
Next ›   Last »