Skip to content
Tech News
← Back to articles

War on Raze

read original more articles
Why This Matters

This article explores the intricacies of optimizing array operations in the APL-inspired language k7, highlighting how language features like raze and rank sensitivity impact performance and code simplicity. It underscores the importance of understanding primitive functions and their alternatives to write more efficient and readable code, which is crucial for developers working with array languages or high-performance computing.

Key Takeaways

WAR ON RAZE

This is the story of what happened when I went down a rabbit hole.

It starts with k7. If you press Ctrl-] in the k7 WASM console, this appears:

x^x*/:x:2_!100

That's a prime number filter. There are faster ones - kparc.com's x,1_&&/80#'!:'x is beautiful - but this one is really short.

The above k7 snippet:

gets the numbers 0 to 99 ( !100 ) drops the first two ( 2_ ), and assigns that to x ( x: ) gets the product of each element in x with each element of x , forming a table ( x*/:x ) then removes the elements in that table from x ( x^ ). And we have it.

The snippet wasn't always so short: it relies on rank-sensitive 'except' ( ^ ), which Arthur introduced around 1 May 2019. Before then, it was this:

x^,/x*/:x:2_!100

This older version inserts a step between #3 and #4: it merges the result of multiply-each-right ( */: ) into a single list via ,/ , also known as 'raze'.

... continue reading