Hacker News new | past | comments | ask | show | jobs | submit login

I'm curious about the Whitney where/replicate monastic operator, and how it replaces 6 or 7 APL operators. My Google-fu was not up to the task.



“Replaces” in the sense that you would use it instead, and not feel like you are missing something, not in the sense that it is equivalent char-per-char.

APL has a few expand/compress operators that take a boolean vector; all of these in K use monadic & (where/replicate), either on the at-index e.g. +/a[&x>3] which is read “sum over a where x is greater than 3”, or at the amend-index, e.g. @[&7 9 15;i:&x>3;:;7-x@|i] which is read “in a vector with seven 0s, followed by nine 1s and fifteen 2s, in the indices where x is greater than 3 (call those indices i), place 7 minus those values from the same indices in reverse order.

Obviously contrived examples, but in APL you’d have to compress/expand a couple of times instead. (Sorry, don’t remember the operator names, my APL is rusty, last wrote a real program in 1992....)


NARS2000, Dyalog APL, and dzaima/APL all have the Where function now. See https://aplwiki.com/wiki/Indices.


I'm not familiar with J but it also appears to have something similar. However the resulting code seems a bit more convoluted than the K version. +/ (I. a>3) { a


More idiomatic J might look like this: +/a#~a>3 .


Thanks! Should probably brush up on my APL, as I have last really used APL2 on a mainframe nearly 3 decades ago.

But I have gotten lazy and too comfortable with K.... oh well.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: