Search code examples
j

"Reversing" a hook in J


I want to put the operation which takes all the items in a list which are greater than 2 into a pointless (as in not explicitly capturing the argument in a variable) function in J. I wanted to do this by using ~ with a hook, like f =: ((> & 2) #)~ but it seems like neither that nor ((> & 2) #~) works.

My reasoning was that my function has the form (f y) g y where y is the list, f is (> & 2), and g is #. I would appreciate any help!


Solution

  • Everything is OK except you mixed the order of the hook. It's y f (g y) so you want

     (#~ (>&2)) y