Vocabulary/atdot

From J Wiki
Jump to navigation Jump to search

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

m@.n Agenda Conjunction

No rank - the result is a verb


(m@.n) creates the verb defined by the n-th atom from gerund m.

   m=: 0: ` 1: ` 2:   NB. a gerund of recognizable sample verbs
   n=: 1
   m@.n    NB. m@.n produces a verb
1:
   (m@.n) ''   NB. The verb can be executed
1

More Information

1. n may be negative to count back from the end of m.

2. If n is a list, a train of verbs is created from the selected items of m.

   m=: 0: ` 1: ` 2: ` 3:
   m@.0 1
0: 1:

3. If n is boxed, each level of boxing indicates a level of parentheses in the verb train

   m@.(0;<1;<2 3)
0: (1: (2: 3:))

4. If only one atom of m is selected, the result of m@.n has the rank of the verb created from that atom. If more than one atom of m is selected, the rank of the created train is infinite.


[x] m@.v y Agenda Conjunction

Rank -- depends on the rank of v -- WHY IS THIS IMPORTANT?



[x] m@.v y executes [x] v y and uses the result to select an atom of the gerund m, which it then converts to a verb w and executes as [x] w y to produce the final result.

   NB. 3 different verbs
   soso =: verb define
smoutput 'Your score was ', ": y
)
   good =: verb define
smoutput 'Your score was ', ": y
smoutput 'Keep it up!'
)
   great =: verb define
smoutput 'Your score was ', ": y
smoutput 'That''s fantastic!'
smoutput 'Would you like to try again?'
)
   NB. Choose them according to score: 7 or less, 8-9, 10
   rate =: soso`good`great@.(7 9&I.)
   rate 4
Your score was 4
   rate 10
Your score was 10
That's fantastic!
Would you like to try again?

Common Uses

1. To get the effect of an if. statement, but with the ability to make the decision for each cell of the arguments. Give v the appropriate rank.

   (%&2)`(>:@(3&*))@.(2&|)"0 ] 1 2 3 4  NB. Divide by 2 if even, triple and add one if odd - checking each atom separately
4 1 10 2

2. To execute different verbs for zero/positive/negative.

   ('nil'"_)`(":)`('neg ' , ":@|)@.*"0  (_5 0 5)
neg 5
nil
5

m@.v on Arrays

Because execution of verbs at low rank is inefficient, u@.v executes at infinite rank but there is an underlying rank implied by m and v.

The implied rank of m@.v y is the rank of the cells of y, each of which produces a result cell. The verbs in m are not applied to these cells directly. Instead, the implied cells of y with identical results i from v are assembled into a list of such cells, and then the gerund i { m is applied to that list of cells. This single application of the gerund must produce one result for each implied cell. The results are assembled, using the original order of the implied cells, into the final result.

The implied rank is -#$ [x] v y, in other words the rank of [x]/y minus the rank of v y. Each gerund of m needs to be able to operate on a single cell of the implied rank, or a list of such cells, giving a result for each cell.

   +:`*:`-:@.(3&|) i. 10
0 1 1 6 16 2.5 12 49 4 18

v y produces a list of 10 numbers, making the implied rank 0. The verbs in m were applied on atoms or lists, and the results were assembled.

   +:`*:`-:@.((3&|)@:(+/)"1) i. 5 10
   0    2    4    6    8   10   12   14   16   18
 100  121  144  169  196  225  256  289  324  361
  10 10.5   11 11.5   12 12.5   13 13.5   14 14.5
  60   62   64   66   68   70   72   74   76   78
1600 1681 1764 1849 1936 2025 2116 2209 2304 2401

v y produces a list of 5 numbers, making the implied rank 1. The verbs in m were applied on lists or tables, and the results were assembled.

   (+/"1)`(<./"1)`(>./"1)@.((3&|)@:(+/)"1) i. 10 10
45 10 29 345 40 59 645 70 89 945
   ((3&|)@:(+/)"1) i. 10 10
0 1 2 0 1 2 0 1 2 0

The gerunds were applied to lists or tables. The "1 is necessary in each gerund to ensure that the gerund produces a result for each cell rather than a result for the array of cells it is applied to.

Related Primitives

Power ([x] u^:v y)


More Information

1. Verb trains cannot be created when v is a verb.

2. Negative selections count back from the end of m.

3. If ([x] v y) has few atoms, the interpreter may choose to execute the gerunds of m on individual cells of the arguments instead of on lists of those cells.


Use These Combinations

Combinations using [x] u@.v y that have exceptionally good performance include:

What it does Type;

Precisions;
Ranks

Syntax Variants;

Restrictions

Benefits;

Bug Warnings

Fast agenda f0`...`fn@.v"0 y All f's must be atomic.

If v has rank 0 then "0 can be omitted