Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

APL Fork/Train with Compression

Tags:

apl

dyalog

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
like image 860
j_v_wow_d Avatar asked Sep 15 '25 06:09

j_v_wow_d


1 Answers

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
like image 178
Adám Avatar answered Sep 16 '25 22:09

Adám