Vocabulary/ampco

From J Wiki
Jump to: navigation, search

>> <<   Back to: Vocabulary Thru to: Dictionary

[x] u&:v y Appose Conjunction

Rank Infinity -- operates on [x and] y as a whole -- WHY IS THIS IMPORTANT?



Applies verb v to each argument in its entirety, and then applies verb u to the result(s) of v

   u =: <                 NB. x is smaller than y
   v =: |                 NB. magnitude
   csm =: +/ @:  u &: v   NB. Count how many x's are smaller than y in magnitude
   _1 2 0 csm 2 _3 0
2
  • Verb v is executed monadically.
  • Verb u is executed either monadically or dyadically depending whether  u&:v has been called monadically or dyadically .

See: More Information for a visual comparison of At (@:), Atop (@), Compose (&) and Appose (&:).


Common Uses

1. u&:v is called for when the rank of v is less than the ranks of an argument, but you want to apply u to the entire result of v.

In the csm example above, we needed (&:) not (&)

   _1 2 0  +/@:<&:|  2 _3 0   NB. "csm" example as an anonymous verb in a 1-liner
2
   _1 2 0  +/@:<&|   2 _3 0   NB. different result using (&) in place of (&:)
1 1 0

Because  | y has rank 0, the entire compound  +/@:<&| is applied to each atom of x and y, making the +/ useless since it now operates on each atom individually.


Related Primitives

Atop (@), At (@:), Compose (&), Hook ((u v)), Fork ((f g h))


More Information

1. Contrast Appose (u&:v) with Compose (u&v) which applies v to individual cell(s) and then applies u on the individual result(s) of v

2. The difference between Appose (u&:v) and Compose (u&v) is shown in the last two columns of the diagram below:

Funcomp.png

The above diagram also shows At (@:) and Atop (@) for overall comparison.

3. So what's the difference between Atop (@) and Compose (&) ?

None at all, for the monads (u@v) and (u&v)

  u&v y ↔ u v y
  u@v y ↔ u v y
But the dyads are different
  x u&v y ↔ (v x) u (v y)
  x u@v y ↔ u x v y

According to the J Dictionary -- &: is equivalent to & except that the ranks of the resulting function are infinite; the relation is similar to that between @: and @