Code examples are in ngn/k, a dialect where int null is 0N
and a list find miss is 0N
, not #list
.
It would be nice if a grouped list gave empty int list for an outdex, and outdex of frequency gave zero. (See here for more.)
x:="abracadabra"
Code examples are in ngn/k, a dialect where int null is 0N
and a list find miss is 0N
, not #list
.
It would be nice if a grouped list gave empty int list for an outdex, and outdex of frequency gave zero. (See here for more.)
x:="abracadabra"
I'm sorry to tell you, but group is gone.
If you check out the latest k.d
on shakti.com as at 28 March 2023, you'll see that 'unary' =
is now 'freq' (frequency).
Group had a long life: it's been around since at least k2, or 1996.
So why did group go? And what should we use instead?
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.
# Unevaluated | |
A `wrap attribute that causes overindexing to auto-mod based on length of list. | |
Avoids mismatch of behaviour of i# and -i#. Cut will auto-fill if not long enough. | |
Negative indexing wraps backwards: (`wrap"abc")[-1] is "c" | |
Requires `null to go back to default behaviour? | |
## Slice as basis for lots of primitives | |
Inspired by ngn's https://chat.stackexchange.com/transcript/message/59004538#59004538 ... |
Thought experiment:
Which k primitives can be implemented as k-strings, reasonably efficiently, with a handful of 'native' built-ins?
Not verified to be in dependency order yet... may depend on the choice of 'fundamental' primitives. Need to do speed tests too.
k9 syntax (download via Shakti). Got a better way to write one? Feel free to comment, you'll be credited!
Mildly interesting results from string analysis of a handful of k files. If you have more public k files or suggestions for further analysis, comment below!
This uses the latest Shakti.
Corpus:
In The APL Orchard, ngn said:
the or-dot-and [∨.∧] trick is one of the most beautiful apl expressions ever, worth staring at :)
Well I had better learn it then...
Apparently it computes a transitive closure of a binary relation. Let's hit Wikipedia.
/ Abstraction considered harmful? One-at-a-time thinking preventing parallelisation? | |
/ AoC 2019 problem 4 | |
```q | |
i:${x+!1+y-x}.`i$"-"\:"193651-649729" | |
/ Results are the same: | |
1~({x~^x}#i)~i@&&/~<':+i | |
/ But the second line (Attila's) is much faster: |