War on Raze

https://news.ycombinator.com/rss Hits: 3
Summary

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'. This raze bugs me. It's a workaround: we wanted a flat list of results from our multiply, but it came out nested, and we had to flatten it manually. How could we have done this without using raze, and without rank-sensitivity? Well, what if each-right isn't the right tool? How else could we have generated the products of pairs? Here's another approach. We split the pair generation and multiplication: x^*/x@!2##x:2_!100 The speed seems about the same, but it's more complicated because we have to manage the generation of indices - measuring how many we need (#), taking a copy (2#), generating index pairs using odometer (!), indexing in (x@), and then multiplying (*/). Could we skip indexing? In an array language? Well... there's another primitive that has a reputation of keeping data flat: You'll know that many 'shallow' k verbs have deep equivalents. Range is just shallow odometer: ![3]~*!,3. At @ is just shallow dot .: (list @ indices) ~ *list . ,indices. Loosely speaking: Shallow verbs take a list in which each element represents an index, and are implicitly one-dimensional. Deep verbs take a list in which each elemen...

First seen: 2026-04-10 08:52

Last seen: 2026-04-10 10:54