K7 Tutorial
cs.nyu.edu
cs.nyu.edu
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.
Upper/lower case:
@1
`i
@1 2
`I
@`a
`n
@`a`b
`N 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 thoughinput[<{...compute weight of element x...}'input]
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 a.map(f)
is basically† just: f[a]
and: a.map(x => m[x])
is still just: m[a]
†: Rank notwithstanding. If that bothers you that f might take an atom, pretend I said f@/:a and m@/:a instead.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.
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.
I'm sure K knowledge and experience ensure the practitioner powerful tools for wide variety of problems in many areas.
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?
There is a Google Group: https://groups.google.com/forum/#!forum/shaktidb
Still waiting for kOS, too.
I'm also still waiting on kOS, but I'll never be able to afford it, so not sure why I'm waiting on it.
While that was the original and still by far most common use case of Anaconda, it has greatly expanded over the past couple of years into a more general purpose software environment packaging tool.
This reminds me of using F# to call out to R. If I have to do all that work, I might as well just use R :). I realize there are some edge cases where that is nice though and that not everyone is as bothered by that as me. It seems like the context switching is inefficient.
It used an interesting idea that exapanded on the ideas of dependencies and triggers to also include GUI updated. There were some special attributes that described the layout of the variable, and you did `show$val to display it. As the value of val changed (and all other values it touched or included), the GUI would updated for you.
Think Excel merged with K and you get the idea.
Most code isn't clever oneliners, and is quite readable.
|/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?But I don't know if that was the motivation / justification for naming these operators / functions.
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
42For 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 &
But, this is not free or open source?
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.
Yes, but they look like this:
https://github.com/tangentstorm/j-incunabulum/blob/master/ji...
Call me crazy, but I'm wary of code written like this.
From the very little APL I've learnt, I know that operators always have either one parameter (named ω) or two (named α and ω), and their inputs and outputs are always arrays.
If you need to write a lot of such functions, it makes sense to define some macros to help you:
#define V1(f) A f(w)A w; // create one-arg function
#define V2(f) A f(a,w)A a,w; // create two-arg function
#define DO(n,x) {I i=0,_n=(n);for(;i<_n;++i){x;}}
iota is the APL equivalent of Python's range function: V1(iota) { // Define one-arg function iota.
I n = *w->p; // Get the value of the ω argument.
A z = ga(0, 1, &n); // Allocate output array.
DO(n, z->p[i] = i); // Assign increasing integers.
R z; // Return the result.
}
The plus function adds two arrays: V2(plus) { // Define two-arg function plus.
I r = w->r, // Get the rank of ω.
*d = w->d, // Get a pointer to ω's data.
n = tr(r,d); // Get tne size of ω's data.
A z = ga(0, r, d); // Allocate output array.
DO(n, z->p[i] = a->p[i] + w->p[i]);
// Add corresponding values of α and ω
R z; // Return the result.
}
Personally I cannot tolerate the lack of whitespace, but the APL guys are known to like to see their entire programs in one screenful. I can understand that some people like to write code like this.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.
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/APL3&4.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...
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.
The first sentence
reminds me a bit of the story of
Mel.
http://catb.org/jargon/html/story-of-mel.html