Arithmetic mean forward or backward?
In the reverse average example, I really don't see a reason that one way would be more efficient than the other (the VVV shape for a fork), but since the forks in J can be asymmetrical (in the NVV shape) I can see some reasons why reversing a mid-fork would be an advantage. Take for example:
(5 # $) 1 2 3 NB. (N V V) form
3 3 3 3 3
(5 #~ $) 1 2 3 NB. (N V~ V) becomes effectively (V V N)
5 5 5
($ # 5) 1 2 3 NB. (V V N) is a syntax error
|syntax error
| ($#5)1 2 3
source to share
Dyadic~
is a "passive" adverb that swaps left and right arguments. Thus, it is the x f~ y
same as y f x
. +/ % #
and are # %~ +/
equivalent. 2 % 5
gives you 0.4
, but 2 %~ 5
gives 2.5
.
Among the places where it can be convenient, you need to check the results of the line with which you are working. While you will probably be experiencing something a little more complicated, you can test yourself by repeating your last line and just adding to the left, without rearranging anything or adding parentheses.
string =. 'J is beyond awesome.'
'e' = string
0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0
string #~ 'e' = string
eee
monadic~
is an adverb "Reflex" that makes the modified verb act like a dyad, duplicating a single argument for both left and right. While this is another shortcut for organizing your arguments, it is very different from the dyadic one ~
. *~ 4
is 16
because you yourself are multiplying y
( y * y
).
source to share