Atomicity

From The K Language Wiki
(Redirected from Fully atomic)

Atomicity is a characteristic attributed to primitives which dictates how a primitive works with arrays and their individual atoms.

Single Argument[edit]

A single-argument(monadic) primitive can be right atomic or non-atomic.


Right atomic monadic primitives will apply their operation to the individual cells of a ragged array:

negate is an example of this kind:

 -((3;5);1)
(-3 -5
 -1)

Try it(ngn/k)

Two Arguments[edit]

A two-argument(dyadic) primitive can be fully atomic, right atomic or non-atomic.


Right atomic dyadic primitives will zip the left atom with each atom present in the right argument:

mod is an example of this kind:

  3!34 2 8
1 2 2

Try It(ngn/k)

Left atomic dyads are a rare sight due to the nature of K's right-to left evaluation, but they are effectively the flipped version of right-atomic primitives.


Fully atomic dyadic primitives can take arrays on both sides, and perform a zipped operation on arbitrarily nested lists, as long as the structure of the arrays allow such an operation(length, distribution of atoms, and so on). They also borrow the characteristics of right atomic and left atomic primitives.

An example of this is add.

  1 3 5+(3; 1 2; 5)
(4
 4 5
 10)

Try It(ngn/k)

Some fully atomic primitives, notably arithmetic primitives allow dictionaries as arguments, and perform their operation across common keys.

 [a:1;b:2;c:3]*[b:10;d:99]
[a:1;b:20;c:3;d:99]
Works in: oK