1

Note that I'm using Dyalog APL for the following.

Given:

      S←'string'
      S
string
      ⍴S
6
      ⍴⍴S
1
      DISPLAY S
┌→─────┐
│string│
└──────┘

If I perform a reduction with concatenation, I get a scalar:

      S_←,/S
      S_
 string 
      ⍴S_

      ⍴⍴S_
0
      DISPLAY S_
┌──────────┐
│ ┌→─────┐ │
│ │string│ │
│ └──────┘ │
└∊─────────┘

Naturally, I can no longer access the elements of my "array". I was wondering why this behavior occurs? I had believed that / acted like foldr and that , produced a vector, so why do I end up with a scalar result at the end?

Thanks in advance for any help.

Sean Kelleher
  • 1,952
  • 1
  • 23
  • 34

1 Answers1

3

I guess you figured out that you can get to yout vector with ⊃S_ - it has been nested.

If you look at the doc of reduction in Dyalog's help, it reads:

R is an array formed by applying function f between items of the vectors 
along the Kth (or implied) axis of Y.

For a typical vector Y, the result is:

⊂(1⊃y)f(2⊃y)f......f(n⊃y)

Notice the ⊂ (enclose) at the beginning! The result is nested - which might be a bit confusing, because you do not experience that with a +/. However, when you look at +/⍳5, this evolves to ⊂1+2+3+4+5 which returns scalar 15 - nesting a scalar does not affect its depth. It's different with ',', because that operation returns an object with a different 'sizing-policy': catenating two scalars creates a vector with two elements. So, as promised, your S_ is a string-vector with 6 elements that has been nested (see definition above).

MBaas
  • 7,248
  • 6
  • 44
  • 61