jtacit-programming

Arithmetic mean forwards vs backwards?


I'm familiar with this way of doing an arithmetic mean in J:

+/ % #

But it's also shown here as

# %~ +/

Are these two versions interchangeable, and if not when should I use one versus the other?


Solution

  • Dyadic ~ reverses the arguments of a verb. x f~ y is equivalent to y f x. You use ~ when you, um, want to reverse the arguments of a verb.

    One of its most common uses is for forks and hooks composition. For example, because y f (g y) is (f g) y you can use ((f~) g) y when you need (g y) f y.