HeadlinesBriefing favicon HeadlinesBriefing.com

K Array Programming Tutorial Shows How to Think in Vectors

Hacker News •
×

A new chapter in razetime's ngn-k-tutorial walks through "Thinking in K," showing how to write idiomatic K code by rethinking imperative patterns. The tutorial uses matrix multiplication as a concrete example, starting from a nested-loop pseudocode translation and progressively stripping away globals, loops, and verbose constructs.

The author demonstrates step-by-step simplification: replacing loops with folds, eliminating intermediate variables, and using eachleft and eachright to pair rows and columns. The process reduces a cluttered 10-line imperative mess into a clean tacit function. Matrix multiplication serves as the vehicle for teaching K's core principle—continuous pattern condensation.

The chapter also covers practical K workflow: using the ngn/k REPL with rlfe history navigation, loading scripts with \l, and testing functions before moving them to files. It references Aaron Hsu's Dyalog '17 talk on APL patterns as further reading. The takeaway is that K rewards developers who stop translating algorithms literally and instead think in arrays from the start.