at least in my experience in k4/q I've seen while used as a way to short curcuit out of big queries on disk when you need to query for something that might be in one of a few partitions of data on disk
@ngn: presumably. Also helps when you port over a complex algorithm from some other language. If you use the "while" forms of over/scan you can't mutate locals
whereas if[]/while[] operate within the same scope
it is more aesthetic to spend more time thinking and re-imagine an algorithm in a vector style, but some things are just really messy
I do like the way guard clauses work in the dfuns APL dialect; it's slightly less expressive than the K :[;;] "cond", but in a good way. I like that, as a special form, guards are explicitly part of the syntax of an anonymous function, whereas in K the special form :[;;] very much looks like it should just be a verb
the handful of instances where it seems like I need to do some sort of branching are done with indexing from a list, just to make a point
conditionals are only inescapable (1) for efficiency sometimes and (2) to terminate general recursive procedures. Obviously sometimes it's clearer to just use a conditional than to do some other contorted thing, but it's a very good educational exercise to try to write some complex code without using them.
@JohnE yes! I must say reading through your section in the oK docs on eliminating conditionals was a great learning experience for me as a budding k programmer! :)
I really tried to capture a bit of the "why" behind the more unusual features in the K toolkit. where/grade/group/encode/decode are sort of the crown jewels of array programming
2
apl and j of course have their own even fancier goodies but they tend to be more special-purpose
the apl world uses "encode/decode" terminology but many people (including myself in the early days) have trouble remembering which is which. i guess "sv/vs" was an attempt to avoid that in k
@JohnE in k or in apl? in k the use of / and \ (or /: and \:) as vs and sv is consistent with what "over" and "scan" usually do - one returns a scalar and the other a vector
it must be "scalar from vector". the docs say /: eachright join|sv
in apl i have my own visual mnemonic for remembering ⊤ and ⊥ - i imagine a two-digit number as input written above a line, e.g. 19, and the result - two separate digits 1 and 9 written below it. so that's ⊤