- Author
- Not stated (razetime ngn-k-tutorial repository)
- Published
- Undated
- Kind
- Tutorial chapter in a GitHub repository
- Original
- github.com/razetime/ngn-k-tutorial/blob/main/12-thinking-in-k.md
- Subject
- Programming languages and types
What it is
This chapter belongs to a tutorial for the ngn/k interpreter. It teaches the habit of condensing patterns by working through one example.
What it says
- The chapter says K programming is a continuous process of simplifying patterns.
- A direct triple-loop translation is called the worst K code the author has written.
- It names the problems: many globals, nested loops and lots of modification.
- A plus fold replaces the innermost loop.
- Each-right and each-left remove the row and column index loops, giving a one-line function.
- Dropping the costly transpose gives a shorter version.
- The final form is a tacit function written as plus-fold of times, applied each-left.
What evidence it gives
The chapter shows each rewrite as code with a short explanation. Outputs were not shown, so the versions were not run here.
Interests and limits
The chapter is a teaching piece, not a benchmark. It claims shorter code is better without measuring speed. It was read in full but the code was not run.