bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] Strange behaviour of ,/


From: Jay Foad
Subject: Re: [Bug-apl] Strange behaviour of ,/
Date: Tue, 4 Feb 2014 09:20:12 +0000

On 4 February 2014 04:17, Elias Mårtenson <address@hidden> wrote:
> Thank you. This made me aware of the fact that I still don't understand
> this. You are right that the rank is zero, shown by the fact that ⍴,/1 2 3
> returns an empty result:
>
>       8⎕CR ⍴,/1 2 3
> ┌⊖┐
> │0│
> └─┘
>
>
> Can you explain to me why that is the case? When I look at the result from
> ,/1 2 3 it looks like an array that contains a single element: another array
> with the values 1 2 3 in it.

Yup, that's right. It's a scalar (a rank-zero array) whose single item
is the vector (rank-one array) 1 2 3.

> But it isn't. The result is rank zero, and I
> can't take the first element from it:
>
>       (,/1 2 3)[1]
> RANK ERROR
>       (,/1 2 3)[1]

This is a mis-use of bracket indexing. With bracket indexing [x;y;z],
the number of indices inside the brackets has to match the rank of the
array you're indexing into, so [1] will only work on a vector. That's
why you get an error.

> But wait, I can take the first element from it:
>
>       ↑,/1 2 3
> 1 2 3

This works because ↑ will give you the first item of an array of any
rank. In fact ↑,/ is a common idiom for catenating a bunch of vectors.

Jay.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]