bug-apl
[Top][All Lists]

## Re: Question on scalar extension of left arg

 From: Kacper Gutowski Subject: Re: Question on scalar extension of left arg Date: Fri, 30 Jul 2021 08:14:58 +0200

Looking at this post I think there is a tiny bug in the implementation of each:
```
(⍳6) {⍺,⍵}¨ ⍳5
1 1  2 2  3 3  4 4  5 5
(⍳5) {⍺,⍵}¨ ⍳6
INDEX ERROR
```
μ-Z__vA_LO_EACH_vB[2] (μ-N⊃μ-Z)←(μ-N⊃μ-A)μ-LO ^ ^
```
I think both should give a LENGTH ERROR.

On Thu, Jul 29, 2021 at 10:48:52PM -0700, Russtopia wrote:
```
```      w
┌→─────┐
│listen│
└──────┘
cl
┌→────────────────────────────────────────────┐
│┌→──────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐│
│└───────┘ └──────┘ └──────┘ └──────┘ └──────┘│
└∊────────────────────────────────────────────┘
```
```
```
w is_anagram_of ¨ cl ⍝ <-- Should this not implicitly expand left arg?
```
```
Look at the shapes, w is not a scalar but a vector of length 6 and cl is a vector of length 5. No scalar extension is possible, but a length error.
```
What you wanted is simply:

(⊂w) is_anagram_of¨ cl
0 0 1 0 1

```
```      (∊1 (⍴cl))⍴⊂w
┌→───────────────────────────────────────────┐
↓┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐│
││listen│ │listen│ │listen│ │listen│ │listen││
│└──────┘ └──────┘ └──────┘ └──────┘ └──────┘│
└∊───────────────────────────────────────────┘
w w w w w
┌→───────────────────────────────────────────┐
│┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐│
││listen│ │listen│ │listen│ │listen│ │listen││
│└──────┘ └──────┘ └──────┘ └──────┘ └──────┘│
└∊───────────────────────────────────────────┘
```
```
```
These are not the same. See that arrow on the left border of boxed representation?
```
```
((∊1 (⍴cl))⍴⊂w) is_anagram_of ¨ cl ⍝ <-- ?? Why does this not work as (w w w w w)?
```RANK ERROR
((∈1(⍴cl))⍴⊂w)is_anagram_of¨cl
^                           ^
```
```
w w w w w       ←→   5⍴⊂w   ⍝ a 5-element vector
((∊1 (⍴cl))⍴⊂w) ←→ 1 5⍴⊂w   ⍝ a 1-by-5 matrix

-k

```