6 ms·
Learning K programming: idiom by idiom [pdf]
- anonzzzies 3y agoNote that there is [0] but Arthur/Shakti[1] are also working on k/fun/junior which should be open source and about 25kb binary. [0] https://github.com/kparc/ksimple https://github.com/kparc/ksimple [1] https://shakti.com https://shakti.com
- mdaniel 3y ago> http://www.finnapl.fi/texts/Idiot.htm http://www.finnapl.fi/texts/Idiot.htm I somehow doubt that is the actual URL, and doubly so since it's 404. I tried URL surgery into http://www.finnapl.fi/texts/Idiom.htm http://www.finnapl.fi/texts/Idiom.htm but that was also 404 and searching for "FinnAPL blue book" didn't cough up anythng
- Eu_RZ 3y agoThis is funny, I copy pasted the URL at the time I was writing and didn't notice that it spelled "Idiot". Anyway, that link is now dead and tosh and moonchild provided good alternates
- moonchild 3y agohttps://aplwiki.com/wiki/FinnAPL_idiom_library https://aplwiki.com/wiki/FinnAPL_idiom_library
- deleted 3y ago[deleted]
- tosh 3y agohttps://web.archive.org/web/20130630212847/http://www.finnapl.fi/texts/Idiot.htm https://web.archive.org/web/20130630212847/http://www.finnap...
- hcfman 3y agoNot to be confused with the language “K” I built for my masters thesis in Auckland in 1985 :-)
- jjtheblunt 3y agowhat's your K like?
- eointierney 3y agoHow antipodean. "I'll make my own from what I have handy." Deepest respects
- anonu 3y agoKDB implements k3. By contrast, Arthur's latest endeavor, Shakti, is k9.
- RodgerTheGreat 3y agoKDB+ provides Q, which is implemented in terms of k4.
- bjconlan 3y agoIt should also be noted that the k4 implementation has evolved since Arthur left/sold to First Derivatives. Kdb 4.1 release touts some nice additions to q [1](syntactically I'm not sure if this cascades into underlying k... I don't have that depth of knowledge) 1 https://kx.com/blog/discover-kdb-4-1s-new-features/ https://kx.com/blog/discover-kdb-4-1s-new-features/
- andoando 3y agoWhy dont the symbols just have names instead of stuff like ||\x. I assume it gets easy to read once you practiced it a bunch but I feel like its such a hindrance to readability/popularity for the sake of appearing simple (look we can reverse a list with a single character!)
- hoosieree 3y agoI assume it gets easy to read once you practiced it a bunch Yup, but for me at least, the learning curve is far gentler than a supposedly simple language like C or Go. After using C professionally for 12 years I still have to look up operator precedence or use cdecl from time to time. Meanwhile I feel like I can store all of K in my head with room to spare.
- pjmlp 3y agoIt is like asking why don't all human languages use the Latin alphabet and use drawings instead.
- dan-robertson 3y agoThe symbols do have names, eg | is commonly called a ‘vertical bar’ or ‘pipe’. I think when people read the code though, they say the name of the operator instead, e.g. your example is ‘reverse max scan x’. A complication is that the meaning of a symbol depends on the surrounding symbols (eg | can be reverse or max) and another is that the meaning can depend on context, eg | is max but when the inputs are arrays of bits (where 1 is true and 0 is false), max is equivalent to logical or, and so people may call the operator ‘or’ in those contexts. I think advocates would claim that the symbols allow for faster interaction with the computer and for larger programs to fit in one’s working memory.
- deleted 3y ago[deleted]
- andylynch 3y agoThat’s roughly where q comes in, as syntactic sugar on top of k
- CuriousCosmic 3y agoNote that this is about K, the APL derivative language for the kdb database software. Not to be confused with K, the rewrite based semantic execution language built by the University of Illinois Urbana-Champaign and now primarily built and maintained by Runtime Verification. https://kframework.org/ https://kframework.org/
- cess11 3y agoLooks like a pretty neat reference to have when dabbling in J as well, which I prefer over Kona for several reasons, including that I can run it on Android. https://www.jsoftware.com/ https://www.jsoftware.com/
- moonchild 3y agosee the phrasebook https://www.jsoftware.com/help/phrases/contents.htm https://www.jsoftware.com/help/phrases/contents.htm
- zX41ZdbW 3y agoI have a somewhat negative experience with Kona and its derivatives Kerf and Kerf2. For example, among Kerf and Kerf2: - there is no explanation about why two versions exist; - the code does not build; - it has memory leaks; - both are abandoned; - there are dubious performance claims, but when I asked the author to clarify, he closed issues without answering. The same experience with the K community: https://github.com/kparc https://github.com/kparc They maintain a cult-like impression of their software, and the examples are typically represented by a few code dumps with no clear way of using them. That's not to dismiss the overall idea of array programming languages, which I admire.
- 7thaccount 3y agoIt is a problem with this community. Until recently kdb+ was like this with barely any documentation. They've come a long way in recent years though on the website and there is at least one book published. With regards to Kerf, I don't know much of the history. I think the Kona developer (Lawler?) and Scott Locklin tried to make a company like kdb+, but it never worked out. Dyalog APL and J both have decent doc.
- 1024core 3y ago> For total water we can use +/ (“sum over”), resulting in +/{((|\x)&||\|x)-x}. And they say Perl is bad.
- huhtenberg 3y agoIt's one of them "write-only" languages :)
- RodgerTheGreat 3y agoPerhaps you could grace us with your clearest alternative in a language you approve of?
- fifilura 3y agoJust for reference, and since I work with Trino these days. The benefit it gives me is that I almost never have to care about RAM or CPU. It just scales in all directions. The negative compared to vector languages is that order is not guaranteed (as can be seen) And the other negative of course is that it is not possible to write generalized functions. I am not saying it is better, but I'll leave it here. And yeah, it does not work with empty arrays. But this is my lunch break! WITH measurements AS ( SELECT index, m FROM UNNEST (ARRAY[3, 2, 5, 5, 3, 6, 5, 7, 2, 9, 2, 6, 1, 7, 2, 6, 9, 1, 1, 4, 2, 9, 2]) WITH ORDINALITY as t(m, index) ), tmp AS ( SELECT index, m, LEAST(MAX(m) OVER ( ORDER BY index), MAX(m) OVER( ORDER BY index DESC)) - m as water_level FROM measurements ) SELECT MAX(water_level) as max_level, SUM(water_level) as total_water FROM tmp
- credit_guy 3y agoI searched in the book for the passage the GP mentioned. It is on page 2, the 6th step in solving an interview problem. The steps are outlined in the book, and the code snippet for each listed. Here they are: 1- Scanning an array x and finding the running maximum is expressed by |\x (read “max scan of x”), the highest altitude to the West. 2- Reversing an array is achieved by inserting a | (“reverse”) before the array. ||\|x (“reverse max scan of reverse x”) will give us the highest altitude to the East. 3- Comparing two vectors element-wise is done with the & (“min”) operation, this is the water level. 4- The element-wise subtraction is -. Adding parentheses to ensure correct sequence of evaluation, and brackets to make it a function that takes an argument, results in {((|\x)&||\|x)-x}. This is a function that returns the height of the column of water at every point. 5- Using this function, we can easily get derived results, for example for the maximum height we can use |/ (“max over”), resulting in |/{((|\x)&||\|x)-x}. 6- For total water we can use +/ (“sum over”), resulting in +/{((|\x)&||\|x)-x} Maybe you find this satisfying, I find it horrendous. Here's the implementation in python/numpy: west_scan = np.maximum.accumulate(A) east_scan = np.maximum.accumulate(A[::-1])[::-1] water_level = np.minimum(west_scan, east_scan) height_water_column = water_level - A max_height = np.max(height_water_column) total_water = np.sum(height_water_column)
- mgaunard 3y agoMy experience when trying to give such tools to data scientists is that they can't use them effectively and will attempt to circumvent the idea of vector programming whenever they can get away with it. They will also often write code that doesn't do what they really want but has the appearance of doing so.
- gitonthescene 3y agoSounds like a problem with the term “data scientist” to me.
- mgaunard 3y agoIs it? The nature of their work is that it's more about reaching the conclusion about what the data says rather than build nice reusable software.
- clircle 3y agoSounds like your data scientists are not big on R.