Hacker News new | ask | show | jobs
by aplorbust 3000 days ago
Anecdote: I frequently use kdb+ for small tasks. For me, its in the "all-purpose" category. The limitations are only in the ability I have to use it.

For example, removing nonconsecutive, duplicate lines from a file, such as a CSV file:

   exec echo "k).Q.fs[l:0::\`:$1];l:?:l;\`:$1 0:l"|exec q >&2;
where Q.fs is a function in a script thats bundled with the interpreter; the chunk size for reading the file into memory is adjustable by editing the function.
1 comments

You can make it simpler:

    l:0;.Q.fs[{if[x~l;:];-1 l::x}each]`:input
or if you have memory:

    -1 distinct read0`:input
...or if you want to use k:

    -1@?0:`:input
Stupid question: With -1, how would I suppress the return value? Use a function?

   k)a:{-1@?0:`:input;};a[]
It's not a stupid question.

    ;
What this does is return generic-null :: which .Q.s doesn't print.