4 ms·
Very nice! I like the readability-- not sure if thats just indicative of your style or the language, and the map construct is also nice. I don't remember any
by upghost 2y ago
Very nice! I like the readability-- not sure if thats just indicative of your style or the language, and the map construct is also nice. I don't remember any off-the-shelf map construct, at least not in Dyalog.
- lokedhs 2y agoIt's likely a combination of both. It's certainly possible to write Kap in a much more condensed form. But things like if-statements and hash maps does allow for a more imperative style.
- xelxebar 2y agoDyalog doesn't have an explicit implementation for maps, but you get the same effect with column-major table stores and the implicit hashmap backing of the search-like primitives [0]. E.g. keys←'foo' 'bar' 'baz' values←1729 42 0.5721 indexOf←keys∘⍳ ⍝ The dyadic ⍳ here is what builds a hashmap Then you can use it like data←(values⍪¯1)[indexOf 'bar' 'bar' 'baz' 'foo' 'invalid' 'foo'] where ¯1 is just the value you want missing keys to map to. If you're okay erroring in that case, it can be left off. For map "literals", a syntax like the following gets you there for now: k v ←'foo' 1729 k v⍪←'bar' 42 k v⍪←'baz' 0.5721 In version 20, proper array literal notation [1] is landing, where you'll be able to do: keys values←↓⍉[ 'foo' 1729 'bar' 42 'baz' 0.5721] In practice, I suspect that this ends up being more ergonomic than actual maps would be in the language. That said K is all about maps and the entire language is designed around them instead of arrays like APL. IIRC, there was also some discussion on the J forums a while back about whether or not to have explicit hashmap support [2]. [0]:https://help.dyalog.com/19.0/#Language/Defined%20Functions%20and%20Operators/Search%20Functions%20and%20Hash.htm?Highlight=hash%20table https://help.dyalog.com/19.0/#Language/Defined%20Functions%2... [1]:https://aplwiki.com/wiki/Array_notation https://aplwiki.com/wiki/Array_notation [2]:https://groups.google.com/a/jsoftware.com/g/forum/c/VYmmHyRooNg/m/gyips1FuAQAJ https://groups.google.com/a/jsoftware.com/g/forum/c/VYmmHyRo...