Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Pearson chrispsn

View GitHub Profile
View war_on_raze.md

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.

@chrispsn
chrispsn / scrapheap.k
Last active Dec 23, 2020
k design scrapheap
View scrapheap.k
[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?
View tables_in_vba.md

Excel Tables and VBA

It's 2020, and there's now many ways to work with data of arbitrary length in Excel:

  • Power Query's M language
  • JavaScript
  • dynamic arrays.

But if you use or support older Excel versions, VBA can still be useful.

View k_tech_tree.md

k tech tree

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!

@chrispsn
chrispsn / dicts.md
Last active Apr 1, 2020
Dicts in k9
View dicts.md

k9 dicts (WIP)

Current in k9 2020.03.27.

Standard lookup:

 [a:1;b:2]`b
2
@chrispsn
chrispsn / k_file_analytics.md
Last active Mar 13, 2020
K usage statistics
View k_file_analytics.md

Analytics on k code

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:

@chrispsn
chrispsn / transitive_closure_k.md
Last active Feb 23, 2020
Transitive closure in k
View transitive_closure_k.md

Transitive Closure in k

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.

@chrispsn
chrispsn / notes.k
Last active Dec 19, 2019
On lambdas
View notes.k
/ 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:
@chrispsn
chrispsn / trees.k
Last active Jan 1, 2020
Trees in k
View trees.k
/ "Apter trees" http://archive.vector.org.uk/art10500340
/ https://github.com/stevanapter/hypertree#concepts
/ http://nsl.com/k/treetable/treetable_k3.html
/ http://www.nsl.com/k/trees.k
/ John Earnest notes https://github.com/JohnEarnest/ok/blob/gh-pages/docs/Trees.md
/ Aaron Hsu talk on high-performance tree wrangling https://www.youtube.com/watch?v=hzPd3umu78g
/ https://www.dyalog.com/uploads/conference/dyalog18/presentations/U19_Tree_Wrangling_the_APL_Way.pdf
/ Translation into k by JE: https://github.com/JohnEarnest/ok/blob/gh-pages/examples/key.k
/ Conquering recursion: http://archive.vector.org.uk/art10501740
/ https://news.ycombinator.com/item?id=21680133 - comments from geocar and John Earnest
@chrispsn
chrispsn / eval_in_context.js
Last active Oct 21, 2019
IE11-compatible version of Brian Beck's eval-in-context
View eval_in_context.js
// https://twitter.com/ua6oxa/status/1170457046153650176
"use strict";
function evalInContext(env, code) {
const
s = JSON.stringify,
locals = Object.keys(env),
keys = locals.map(function(k){return s(k)}),
values = locals.map(function(k){return env[k]}),
body = s("return eval(" + code + ")")