cancel
Showing results for
Did you mean:

## Missing some items

Valued Contributor

We encounter the `enlist` keyword early in learning q; a reliable way to make a one-item list where `1#` won’t do. But there is a bit more to `enlist` than that.

In the first place, it is not only variadic – taking various numbers of arguments – it will take any number of arguments, even more than eight.

``````q)enlist[`one;`two;`three;`four;`five;`six;`seven;`eight;`nine]
`one`two`three`four`five`six`seven`eight`nine``````

Of course, what it returns is a list, with each argument an item.

``````q)enlist[`one;`two;`three`and`a`bit;`four;`five;`six;`seven;`eight;`nine]
`one
`two
`three`and`a`bit
`four
`five
`six
`seven
`eight
`nine``````

What is less obvious is that `enlist` is implicated in lists with missing items.

``````q)type (`one;`two;`three)  / symbol vector
11h
q)type (`one;::;`three)  / mixed list
0h
q)type (`one;;`three)  / a -- projection?
104h
q)(`one;;`three) ~ enlist[`one;;`three]
1b``````

Is the missing item a generic null? No, a list with one or more missing items is a projection of `enlist`, and its rank is the number of missing arguments. We can apply and iterate it as any other projection.

``````q)(`one;;`three;;`five)[`two;`four]
`one`two`three`four`five
q)(`one;;`three;;`five) . `two`four
`one`two`three`four`five
q)raze `quick`crafty`cunning(`the;;`brown;;`jumps)/:\:`fox`cat`dog
the quick   brown fox jumps
the quick   brown cat jumps
the quick   brown dog jumps
the crafty  brown fox jumps
the crafty  brown cat jumps
the crafty  brown dog jumps
the cunning brown fox jumps
the cunning brown cat jumps
the cunning brown dog jumps``````

Which gives us a few tricks up our sleeves when generating test datasets, or preparing data for loading and ingestion.

1 Comment
Moderator

Thank you very much for sharing @SJT

Great q-bie content here 👏