2

I've been using Dyalog APL for a class assignment and I've run across an issue in transforming each element of a nested array.

I have a character array called HOLD which has a variable amount of 7 character long arrays in it. Using a split transformation I can turn it into a nested array of readonly nested arrays, however I need them to be to be character vectors.

I can individually change an element into a character vector with the MIX operator,

TEST←↑HOLD[1]  ⍝Test will be a character vector

but I can't seem to do this to every single element at the same time.

My best attempt looks like

TEST←↑¨HOLD ⍝Test will be a nested array, seemingly identical to hold

but this seems to leave each element as readonly character array. How can I preform this operation on every element in HOLD at the same time and get a resulting nested array of only character vectors?

  • 1
    I'm curious as to what of class uses Dyalog APL... I'm a bit confused by your question. A character array holds characters, not other arrays. An example would be nice. – Pavel Mar 06 '18 at 05:29
  • Apologies for being unclear, the original character array is just a list of random alphanumeric characters, with every 7 characters starting a new line. For example: AIG67QC C12TOBL W1ZKGG2 I'm not sure how APL handles newlines, but each set of 7 characters is on a newline in my original character array. – Brendan LeTourneau Mar 06 '18 at 06:55
  • The course is a general programming language class at my university. It's basically an overview of many different languages, and it's a required course for Computer Science majors. – Brendan LeTourneau Mar 06 '18 at 07:07
  • 1
    Does [this](https://stackoverflow.com/questions/46821632/problems-when-trying-to-use-arrays-in-apl-what-have-i-missed) help you? – Adám Mar 06 '18 at 07:37

1 Answers1

2

What you're looking for is the "enlist"-primitive. It requires ⎕ML to be >0, so I'm assigning it within a dfn (to keep scope local): TEST←{⎕ML←1 ⋄ ∊⍵}HOLD

If your ⎕ML is already >0 (see status bar), you can simply do: TEST←∊HOLD

Try it online!

MBaas
  • 7,248
  • 6
  • 44
  • 61
  • I think my problem may lie in getting the elements at certain indexes. I tested with your example of foo←'I' 'am' 'a' 'vector' 'of' 'text' 'vectors'. When I set bar←foo[4], it shows the object as a readonly nested array instead of a vector. I appreciate the help! – Brendan LeTourneau Mar 06 '18 at 07:17
  • Well, it's not exactly "readonly", you can always overwrite it! ;-) In order to get the content of the element AND remove that one level of nesting, do `4⊃foo`. You could also do `∊foo[4]` which looks similar, but is not. Try: `foo[4]←∊'multiple' 'strings'`and experiment with the previous statements! ;-) – MBaas Mar 06 '18 at 07:22
  • Sorry, typo! I meant "...try `foo[4]←⊂'multiple' 'strings'` – MBaas Mar 06 '18 at 12:12