Where: Difference between revisions

From The K Language Wiki
Content added Content deleted
No edit summary
mNo edit summary
Line 6: Line 6:
&0 0 1 1 0 1
&0 0 1 1 0 1
2 3 5
2 3 5
For a single integer it generates that many zeroes:
For an integer atom it generates that many zeroes:
&3
&3
0 0 0
0 0 0

Revision as of 21:58, 8 July 2021

Where
&x

Where replicates each item in the domain of a list or dictionary as many times as the corresponding value (which is required to be a non-negative integer) in the range:

 &1 0 1 4 2
0 2 3 3 3 3 4 4

For a boolean list it returns the positions of the truthy items:

 &0 0 1 1 0 1
2 3 5

For an integer atom it generates that many zeroes:

 &3
0 0 0

For a dictionary it uses the keys instead of indices:

 &`a`b!2 3
`a`a`b`b`b

Deep where

A non-standard extension in ngn/k works on matrices and higher-dimensional arrays. It returns the paths to truthy atoms as the columns of a matrix:

 glider:(0 1 0;1 0 0;1 1 1)
 &glider
(0 1 2 2 2
 1 0 0 1 2)