Current in k9 2020.03.27.
Standard lookup:
[a:1;b:2]`b
2
Index into something else with a dict to label the results:
`corn`field@ [a:1;b:0]
a|field
b|corn
Regular vs step (_
) functions (partial vs total):
( 1 3 5!"abc")@!7
" a b c "
(_1 3 5!"abc")@!7
" aabbcc"
Sort by values (<>
):
!3#> [food: 200; data: 150; rent: 800; candles: 3600; utility: 150]
`candles`rent`food
^ NB: may be more efficient to keep keys and values separate, eg: https://news.ycombinator.com/item?id=22746372
TODO show an example that benefits from fact that dicts can have duplicate keys
Merge dicts (dicts on right have precedence) and sort by keys (^
):
sched1: 2020.03.31 2020.04.01!`party`doctor
sched2: 2020.04.01 2020.04.03!`prank`gym
^sched1,sched2
2020-03-31|party
2020-04-01|prank
2020-04-03|gym
Tables are lists of dicts. Merge tables (no way to determine date collisions):
sched1: [[]date: 2020.03.31 2020.04.01; appt:`party`doctor]
sched2: [[]date: 2020.04.01 2020.04.05; appt:`prank`gym]
^sched1,sched2
date appt
---------- ------
2020-03-31 party
2020-04-01 doctor
2020-04-01 prank
2020-04-05 gym
Or as keytables (which are just dicts mapping a table to a table):
sched1k: [[date: 2020.03.31 2020.04.01] appt:`party`doctor]
sched2k: [[date: 2020.04.01 2020.04.05] appt:`prank`gym]
^sched1k,sched2k
date |appt
----------|-----
2020-03-31|party
2020-04-01|prank
2020-04-05|gym
We could have instead used the key
verb:
s1keyed: `date key sched1
s2keyed: `date key sched2
^s1keyed,s2keyed
date appt
---------- -----
2020-04-01 prank
2020-04-05 gym
Unkey a keyed table:
s1keyed
date |appt
----------|------
2020-03-31|party
2020-04-01|doctor
() key s1keyed
date appt
---------- ------
2020-03-31 party
2020-04-01 doctor