2 ms·
I think that k3 example does illustrate weaknesses of k3. At that time, dictionary types were very limited and inexpressive. Pretty much all you could do with t
by RodgerTheGreat 7y ago
I think that k3 example does illustrate weaknesses of k3. At that time, dictionary types were very limited and inexpressive. Pretty much all you could do with them was index into them and destructure them.
In k5/k6, dictionaries had a more complete algebra. If you only wanted to take the union of a set of dictionaries (more common) it's just raze:
,/([a:1];[b:2];[a:3;c:4])
[a:3;b:2;c:4]
The full problem could be expressed as
{k!{x@&~^x}'x@'/:k:!,/x}
Note that there's no longer any clumsy transposition to assemble the dictionary; generally much less nesting as well. The syntax for creating symbol-keyed dictionaries is also much nicer.
Something that apparently I left on my workbench for oK was the "adverb form" of drop (_), which would let you express filter more directly:
{k!(^:)_:'x@'/:k:!,/x}
- kazinator 7y agoI added some arguments to TXR Lisp's hash-uni (which merges two dictionaries) to be able to do this. It already has an optional join function to resolve values with clashing keys. Now it will take two additional functions to map the left and right values. If we have a pair of dicts with values that we'd like to list, we can do [hash-uni h1 h2 append list list]. The values are turned into lists, and clashes resolved with append. A list of hashes could be merged into lists with left-reduce, like this. [reduce-left (op hash-uni @1 @2 append : list) hashes #H()] Our initial value is an empty hash #H(). The reduce kernel function is hash-uni. The values of every has in hlist are turned into one element lists, and then accumulated onto the lists in the hash merged so far with append. The initial accumulator is the empty hash. It's more than vaguely monadic: the two functions are like "unit" and so on.