Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

APL Fork/Train with Compression

I want to select elements from an array based on some test. Currently, I am trying to do that with a compression, and I would like to write it as a tacit function. (I’m very new to APL, so feel free to suggest other options.) Below is a minimal (not-)working example.

The third line below shows that I can use the testing function f on vec and then do the compression, and the fifth line shows I can apply the identity function to vec (as expected). So based on my understanding of the train documentation, I should be able to make a fork from f and with / as the center prong. Below shows that this does not work, and I presume it is because Dyalog is interpreting the sixth and eighth lines as doing an f-reduce. Is there a way to indicate that I want a compression train and not a reduce? (and/or is there a better way to do this altogether?)

      vec ← 10⍴⍳3
      f ← {⍵≤2}
      (f vec) / vec
1 2 1 2 1 2 1
      (f vec) / (⊢ vec)
1 2 1 2 1 2 1
      (f/⊢) vec
1
      (f(/)⊢) vec
1

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Yes, by making / an operand, it is forced to behave as a function. As per APL Wiki, applying atop the result of / solves the problem:

      vec ← 10⍴⍳3
      f ← {⍵≤2}
      (f⊢⍤/⊢) vec
1 2 1 2 1 2 1
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading