9 ms·
K7 Tutorial
- ne01 8y agoOff topic, but is it just me, or do you also dig the simple text format of the website? -- so easy to read!
- jchw 8y agoWish it didn't have manual line breaks, though; it's kind of terrible on mobile.
- Stratoscope 8y agoThe first sentence reminds me a bit of the story of Mel. http://catb.org/jargon/html/story-of-mel.html http://catb.org/jargon/html/story-of-mel.html
- pvitz 8y agoThe mentioned gitlab repo doesn't seem to exist anymore. One would have to download kdb+ from kx, but I am not sure if this wouldn't be K4 only. Alternatively, one could play with oK (K6) which would also give you the nice graphical iKe.
- chrispsn 8y agoK7 is now available as a trial from Shakti Software, Arthur Whitney’s new company. https://anaconda.org/shaktidb https://anaconda.org/shaktidb There is a Google Group: https://groups.google.com/forum/#!forum/shaktidb https://groups.google.com/forum/#!forum/shaktidb
- ah- 8y agoI didn't really follow that development, what led to the creation of Shakti?
- 4thaccount 8y agoNot really sure... people started talking about it on the mostly dead /r/apljk subreddit last week which caught my attention. It appears Arthur Whitney left Kx Systems and started his own company again. I'm immediately suspicious when I see "blockchain" in something, but Arthur is a bit of a legend. I don't fully understand why it is bundled as an Anaconda (scientific and data analysis oriented distribution of Python), but I assume a library is utilized there for machine learning or something like that (hopefully someone can comment and tell us what). You can type in "/" in the REPL to bring up the help menu showing the various symbols and what they mean monadically (when taking one argument) or dyadically (taking two arguments). As usual though, their website seems to have virtually zero documentation like they want to stay obscure. I'd love if someone in the industry that can afford to use these products can tell me what Shakti looks like it would be used for. Is it the same as kdb+ mostly with a few added features?
- pvitz 8y agoAccording to the Google Group, Alexander Belopolsky (involved in pyq) is a member of Shakti. That would explain the Python relation.
- chrispsn 8y agoI've played around with the Python integration - it's pretty smooth. See, eg, https://groups.google.com/d/msg/shaktidb/lQ3XSvFPDhw/DOlmmFgHDAAJ https://groups.google.com/d/msg/shaktidb/lQ3XSvFPDhw/DOlmmFg...
- deleted 8y ago[deleted]
- toastking 8y agoI think the reason it's in anaconda is they're trying to go after the python crowd? Regain some of the data analysis market share that stuff like numpy took from APL.
- 8y ago
- avmich 8y agoWhat's important is that APL language family isn't a domain-specific one, suitable for some particular tasks in a narrow niche. To the contrary, they are languages of computations, allowing rather short paths from thought to implementation of an algorithm, compared to other languages. I'm sure K knowledge and experience ensure the practitioner powerful tools for wide variety of problems in many areas.
- a-saleh 8y agoStill, for me it is quite hard to imagine what would I create with APL. Usually, when trying a language, my instinct is to implement a web-service. Or a simple gui-app, with some library. With APL, I am looking at it and wonder. I looks powerful. But what should I do with it? Make a compiler? A database? How does I/O even work there?
- toastking 8y agoIn K, usually the I/O primitives you have are the "colon" operators, stuff like 4:.
- ngcc_hk 8y agoDifference between J7 and K7?
- 4thaccount 8y agoJ and K are different languages. They are similar in that both use standard ascii keys and are in the APL family of languages. The author of K "Arthur Whitney" wrote part of a prototype with Roger Hui for the J interpreter or so I think. The primary author of J is none other than Ken Iverson (the Turing award winner and designer of the original APL) who wanted a free version of APL for the masses where people wouldn't complain about the weird non ASCII APL symbols. It also primarily uses a tacit function train style of programming like data flow languages where you don't even necessarily need variables (pretty cool). This tacit coding style has since been added to Dyalog APL where you can see folks like Aaron Hsu build some pretty cool applications using it. I'd imagine K is more performant though than J and the source is famously small (just a few C files). J has a lot more stuff baked in like Qt support. They both have a database library Jd (for J) and Kdb+ (for K). Kdb+ is a fancy SSD based database which uses K and a SQL like DSL called Q. Its performance is pretty darn good and used in Finance. I don't know enough about Jd.
- etatoby 8y ago> [K's] source is famously small (just a few C files) Yes, but they look like this: https://github.com/tangentstorm/j-incunabulum/blob/master/ji.c https://github.com/tangentstorm/j-incunabulum/blob/master/ji... Call me crazy, but I'm wary of code written like this.
- 4thaccount 8y agoThis comes up a lot in these discussions and I believe Arthur better understands 6 pages of code written like that than someone else can comprehend 30 pages of the equivalent idiomatic code. He writes APL/K for a living, so making the C fit closer makes more sense in my eyes as it matches his thought process better. I sympathize with hating scrolling in how it hurts your ability to see everything at once.
- 8y ago
- quickthrower2 8y agoCan any comment how this compares to R? Seems to have similar capabilities.
- et2o 8y agoThe syntax seems vaguely similar, but I don't really see other commonalities. R's strength is it's incredible ecosystem.
- pmontra 8y agoThe language looks generally good for its goal, except these two operators |/y / maximum &/y / minimum Those two characters have no connection with the operation they stand for and seem to be randomly picked from the available symbols on the keyboard. Why not simply max y and min y, which anybody can read and understand?
- deleted 8y ago[deleted]
- i_don_t_know 8y agoAt least for boolean operations, | (or) can be thought of as the maximum of a vector of 0s (false) and 1s (true). Likewise, & (and) is the minimum of a vector of 0s (false) and 1s (true). But I don't know if that was the motivation / justification for naming these operators / functions.
- uryga 8y agoif you squint a bit, `x or y` returns the one that's greater, i.e. `0 or 1 == 1`; and `x and y` returns the one that's smaller, i.e. `0 and 1 == 0`. so min/max kind of are a generalization of and/or
- pfortuny 8y agoThose are “or”=max, “and”=min. They are use sometimes in Mathematics (I have used them) but with the “low angle” and “up angle”. Not too frequently though.
- lelf 8y agoParaphrasing fold[max] y # maximum fold[min] y # minimum Those two characters have no connection with the operation they stand for | — logical-or, min & — logical-and, max 0|1 1 1|42 42
- de_Selby 8y agoSure they do, in most C-like languages || is OR and && is AND. For OR, from 1 | 0 = 1 It's a small step to generalise to N | 0 = N (~max) and then N | N-1 = N (max) The same goes for &
- maxpetis 8y agoYeah I could really use that. I'd like to take advantage of its enhanced BCLK capabilities but every time I mess with it it doesn't POST. https://www.assignmentland.co.uk/ https://www.assignmentland.co.uk/
- elizabeth_olu 8y agowww.elizabethblog.com.ng
- mark_l_watson 8y agoI liked the example of 1 line of code generation a table of random stock data. But, this is not free or open source?
- toastking 8y agoThere is an open source port of K called Kona: https://github.com/kevinlawler/kona https://github.com/kevinlawler/kona
- codetrotter 8y agoIt’s not a port, it’s a separate implementation. The difference in meaning between these two words is sufficiently important that it’s worth pointing out IMO. Porting software means to adapt an existing piece of software to a different computing environment. Ports are based on source code and/or assets from the original piece of software that is being ported. As such a port would be derivative work, meaning that the authors would not be able to release their software without permission from the copyright holder(s) of the software that was being ported.
- didsomeonesay 8y agoInteresting previous discussion of K programming languages (up to K5): https://news.ycombinator.com/item?id=16500908 https://news.ycombinator.com/item?id=16500908 (2005)
- patrickg_zill 8y agoTrying to learn how to use A+ from aplusdev.org to do some simple work for my personal use. A previous language designed by Arthur Whitney and GPL also. Included in Debian derived distros btw.
- etatoby 8y agoI would highly recommend GNU APL over A+. GNU APL is a full-fledged, modern implementation of the official ISO APL 2 standard, supporting things like Unicode and modern terminals, and is currently maintained by very friendly people. While A+ is a very old, partial implementation of APL that requires a dedicated font and 8-bit encoding to work, and has not been maintained for decades. (IIRC) Documentation for APL 2 can be found online, but I would recommend getting a second hand copy of the classic Gilman Rose book. I bought mine online for a few dollars.
- patrickg_zill 8y agoIs there a particular edition of the Gilman Rose book you would recommend?
- etatoby 8y agoSorry for the late reply. I seem to have the 1976 edition (I didn't think of checking the edition before buying mine! DOH!) I would say it was good enough for learning the language, although the references to mainframes and terminals are obsolete. (Picturesque, if you like that sort of thing, but obsolete.) If you can get the latest edition (1991) it's probably better. I ended up buying that book because from all the online resources I was able to find at the time, I failed to understand the gist of the language, or how you are supposed to think in order to solve problems in APL. Which is profoundly different from all other languages, and which the book taught very well. I've also been using paper books to learn programming since forever, so it's a workflow I'm used to. That being said, there are some free resources that you could try first: http://misc.aplteam.com/robertson/APL1&2.pdf http://misc.aplteam.com/robertson/APL1&2.pdf - http://misc.aplteam.com/robertson/APL3&4.pdf http://misc.aplteam.com/robertson/APL3&4.pdf - https://www.dyalog.com/uploads/documents/MasteringDyalogAPL.pdf https://www.dyalog.com/uploads/documents/MasteringDyalogAPL.... The latter is about Dyalog APL, a dialect of APL, so not all of it will be applicable to GNU APL. About the font, any Unicode font will do, but for graphical consistency I would recommend downloading this one. You can use it with any modern terminal application: https://www.dyalog.com/uploads/files/download.php?file=fonts_and_keyboards/Apl385.ttf https://www.dyalog.com/uploads/files/download.php?file=fonts... About the keyboard, if you are on Linux you can just add one of several APL variants to your existing national keyboard. You will have to designate an APL key (eg. the useless menu key) to use as a special alt-like key to input APL symbols. If you're not comfortable typing blindly, you can buy a keyboard with APL symbols on it, or alternatively buy or print stickers to apply to yours. I spent an entire summer learning APL for fun (that was way before GNU APL existed, so I had to struggle with various proprietary interpreters, either freeware or demoware, on top of the weird language + font + keyboard!) I then went on to compete in Code Golf challenges and other random things using it and had a blast! I still miss APL. IMHO none of the successors (J, K) come close to the beauty of its symbols. It's also a very different way of writing algorithms (sometimes called "multi-dimensional array programming") that is not found in modern programming languages. Feel free to contact me (username + gmail) for any questions you may have.
- yiyus 8y agoIt's a very good tutorial (it's not easy to find information about k7), but it is a bit outdated. For example, % is inverse and not sqrt now, and it is not possible to evaluate parsed trees with !. I am sure the differences are small, but be prepared to be surprised with some descriptive error messages like: 'nyi
- pvitz 8y ago'nyi = not yet implemented
- yjftsjthsd-h 8y agoAnd that's very obvious once it's been pointed out, but how long would it take a beginner to figure that out?
- pvitz 8y agoI agree that the official K documentation was/is thin (after the K2 manual). But if you are interested in it, John Earnest wrote a nice documentation: https://github.com/JohnEarnest/ok/tree/gh-pages/docs https://github.com/JohnEarnest/ok/tree/gh-pages/docs
- yiyus 8y agoA beginner is going to have a bad time with any language. Sure, 'nyi is not very descriptive, but an error message is not the place to teach total beginners. Unless you put some effort into learning a language (or already know something similar), compiler errors will be difficult to figure out anyway. The most blatant example is the infamous "discards qualifiers" error but, for example, in a programming language with nice and descriptive error messages like Go, you will have a hard time figuring out what a interface type error is about until you actually read the manual and learn what an interface is.
- smacktoward 8y agoA good error message doesn't have to be descriptive, but if it isn't, it absolutely must be Googleable -- i.e. unique enough so that someone who doesn't understand what it means can paste it into a search engine and find out. If I Google "'nyi", I get a bunch of results about the New York Islanders hockey team. Not helpful. If I try to be more specific and Google "'nyi k7", the closest thing to a helpful result I get is a link to this discussion on HN.
- twohoursprog 8y agoAny good programmer should be able o learn to program k7 at the level of this tutorial in two hours.
- vadiml 8y agoK7 like it's ancestor APL is extremely powerful language, whit great signal to noise ratios. However it is kind of "write-only" language.. When trying to read a code not written by you (or written by you couple of monthes ago) you struggle to understand it...
- toastking 8y agoK is interesting in that unlike something like Java the hard part is not remembering the standard library. You start to learn idioms for how to do certain things as you use it more. Then you pattern match different parts of the code and it can be very readable.
- icen 8y agoI think that this is a matter of practice. I write k/q almost daily, and don't struggle to read other people's code, or my own. Most code isn't clever oneliners, and is quite readable.
- anonu 8y agoAgree with this. The problem is that there's no widely adopted style guide with k or q. A lot of code you find on the web is written in a minified fashion. At least put a new line and indent whenever you can.
- stefano 8y agoThe fact that every function/operator has multiple meanings, often very different, depending on the actual data passed to it doesn't help readability. It tries too hard to use only symbols, which are limited on an normal keyboard, and so it crams multiple functionalities into the same symbol.
- surajs 8y agoGitlab link to download it is a 404!?
- toastking 8y agoA concept in K that I wish more languages had is indexing with a list of indices. It always blows peoples' minds when I tell them how sorting works in K. You use grade (<) to return the indices that will sort the array if indexed in that order. Then you pass in that list as the indices to the list. They do it in the string examples in this tutorial.
- i_don_t_know 8y agoSorting a list by getting the sorted indices (permutation) and then applying them might seem a bit roundabout at first glance. Then you realize that you can apply the permutation to something else. For example, to sort a table by the values of a column, you get the column, "sort" the column, then apply the permutation to the original table (all columns of the table).
- faitswulff 8y agoHow does grade work? Can you customize how it ranks results?
- i_don_t_know 8y agoIf you want to rank results differently, you'd apply a function to each element of the original vector that computes the rank / weight of that element. Then you sort by weights, and apply the result to the original vector. Something like: input[<{...compute weight of element x...}'input]
- toastking 8y agoThis is also how filtering works, you map a function that returns 0 or 1 over the list. Then you can call where (&) and it will give you the indices where the function evaluates true. Index by that and you'll filter a list.
- icen 8y agoA related operator is group (=), which creates a map between the unique elements of a list to their locations. x: 10 ? `a`b`c x `a`c`c`c`c`a`b`a`a`c =x a|0 5 7 8 b|,6 c|1 2 3 4 9
- beaumayns 8y agoI was hoping we'd finally get proper lexical scope in this version of K. Alas, seems to not be the case.
- yiyus 8y agoThere are a few expected (or, better said, rumored) features that have been left out. Some of them will eventually come (views), some of them probably don't (like using the unicode symbol for sqrt). I was surprised when I saw in nsl a shift-reduce parser that took into account operator precedence, but it looks like it is not being used. I'd like to have lexical scoping too, but due to how function values work, I see it very unlikely.
- asimjalis 8y agoWhat are the financial applications that this is used for? Does anyone have specific examples?
- bwanab 8y agoIn the 1990s Morgan Stanley's full suite of fixed income portfolio management and trading applications were written in APlus which was another of Arthur Whitney's APL variants. When I joined, MS was moving away from it, but the developers who'd been using it were very much in the "you'll take APlus from my cold, dead fingers" camp.
- alfalfasprout 8y agoNot K7, but KDB+ is the de-facto time series store for financial data. It's faster than anything open source by orders of magnitude and extremely expressive. However, it's extremely expensive. If KDB had a much more user-friendly licensing scheme they would have seen much more adoption.
- svnpenn 8y agois it a private repo? this is asking me to login https://gitlab.com/k7db/k https://gitlab.com/k7db/k
- anonu 8y agoI think so - I can't clone
- twohousprog 8y agoOk. Hoy are given 3 hours
- sannysanoff 8y agoFor curious, several facts i noticed by running anaconda distributed shakti: 1) k7 implementation obviosly is completely different codebase from current kdb+. I ran the following query on kdb+ and k7 a1:1000000?1000000;b1:1000000?1000000; \t select #a by b from (+`a`b!(a1;b1)); And difference seems to be in order of magnitude (k7 is 650 msec, kdb+ is 77 msec), also on k7, time increases for subsequent execution of same query ==> memory leak? Looks like it's very early stage. 2) null number (0N) and infinity are now represented as non-ascii symbols Ø and ∞, also parsed as such. 3) type operator (@) returns symbols (`i, `j) for ints and longs etc, was returning shorts before. Interesting how do we distinguish arrays/scalars now. 4) default numeric type (e.g. 12345) is now int, was long. 5) entering overflow numeric literal returns Ø, was throwing exception. 6) k in anaconda is not stripped 675K linux x64 executable, stripped is 220K, while kdb+ is 657K as sold.
- pvitz 8y agoOne might add that by typing "\", the K7 description gets printed (similar to the description on kparc.com).
- chrispsn 8y agoPerhaps the performance difference is due to resource limitations in the Shakti trial?
- SifJar 8y ago> 3) type operator (@) returns symbols (`i, `j) for ints and longs etc, was returning shorts before. Interesting how do we distinguish arrays/scalars now. Upper/lower case: @1 `i @1 2 `I @`a `n @`a`b `N
- sannysanoff 8y agoI saw that, but how do you make simple check if it is uppercase?
- SifJar 8y agoI guess you can check the ASCII value of the char: li:{(*$@x)within "AZ"} li 1 0 li 1 2 3 1 Or can have a list of uppercase chars as names & check with 'in': li2:{(@:y)in x}[`$,:'`c$"A"+!26] li2 1 2 3 1 li2 1 0 'li2' seems to be considerably faster: \t:10000 li 1 2 3 13 \t:10000 li2 1 2 3 6 There may well be a better way though