Talk:K (programming language)

Latest comment: 9 years ago by John Vandenberg in topic q syntax highlighting lost

Untitled

edit

Is http://www.schneier.com/code/sol.k in this "K programming language"? — Preceding unsigned comment added by 207.65.110.114 (talk) 05:14, 10 February 2005 (UTC)Reply


yes. — Preceding unsigned comment added by 62.56.55.49 (talk) 16:59, 25 January 2006 (UTC)Reply

NPOV

edit

I'm missing NPOV here. Seems like this entry was written by the language designer, or (more likely) somebody who's using the language and a bit too fond of it.

Nothing wrong with that in itself, but not very informative - if somebody says "combines the best of foo, bar, and baz", I still don't know *which* features of foo, bar, and baz went into the language.

<rant> The section on the Hello World program is entirely misguided. Nobody is interested in how easy it is to write a Hello World program (except those who're learning the language, and the interest persists only until the program runs).</rant> (Sorry for ranting, but the section really deserves it. IMHO.)

Joachim Durchholz — Preceding unsigned comment added by 84.175.172.16 (talk) 06:59, 17 May 2005 (UTC)Reply

I like the Hello World program because it can give you an immediate sense of the language. A comparison of the K example with a comparable example from Java is representative of the differences between the two language in general. However I certainly agree that you need additional examples. I've added a word sort and prime number examples since they were the two examples used in the APL section. If you want a different example or additional ones say something and I should be able to help.

Abcarter 13:37, 25 November 2006 (UTC)Reply

completely agree! Claims like "speed" and "expressive syntax" should be backed with facts and definitions. Fast compared to what? What does expressive mean? A language is expressive to the extent that it is able to expresses the solution using abstractions from the problem domain. K expressions look like noise on an excessively long and capacitive RS-232 connection. It's possible that they are expressive if the surface syntax is transliterated into a notation which is readable. In 2011, it is not important to be able to cram an entire application onto a single 80 column punched card. That is not what "expressive" ought to mean, in any case. 24.85.131.247 (talk) 16:50, 29 September 2011 (UTC)Reply

Out of date?

edit

I followed the kuro5hin discussion, and looked at the Kx Systems website, but failed to find any information about how to get hold of K.

Along the way I found K Links put up by the other of the kuro5hin article, and "No Stinking Loops", a collection of links for various APL-derived languages; interpreting the latter my best guess is that versions 2 and 3 of K are obsolete and version 4 is now called "Q".

The link to "K4/Q" throws you into a directory which appears to contain libraries for the Q runtime, but there isn't much in the way of documentation there to tell you what to do with them.

Maybe this will help someone work out how to improve the current article ... Hv 02:24, 8 February 2006 (UTC)Reply

Free?

edit

Anyone found any evidence that K is free for free software? I've gotten nothing but rude responses from their sales people.. note I said sales. :) 216.199.93.178 20:59, 6 June 2006 (UTC)Reply

It used to be the case that you could download a demo version of K from the Kx website. However, in 2003 Kx systems released Q which merges the features of K and Ksql and is meant to be the successor to both. At some point they deleted the K download since it is no longer a featured language; however they did not add a Q download. Kx still offers trial versions of Q, but it is on a by request basis. Abcarter 15:05, 25 August 2006 (UTC)Reply

You can download an older version of K for linux from http://cs.nyu.edu/cs/faculty/shasha/papers/klinux. Other version are referenced in http://www.cs.nyu.edu/shasha/papers/cousins.html. I hope Kx Systems would consider once again providing official access, but without any support, to the last version of K prior to Q as this is an excellent language. Bakul Shah 18:54, 29 November 2006 (UTC)Reply

A correction and a comment. I had thought that Q was the successor to both ksql and k. It is the successor to ksql and it does merge the features of ksql and k, however it is still written entirely in k, though a newer version. It would be nice for Kx to offer older versions of k without support, but it's not clear that it is in their interest to do so. Abcarter 00:19, 1 December 2006 (UTC)Reply


Proposed merge with KDB

edit

Unless there are objections I will begin the process of merging the entry on KDB (database) with K (programming language). This is based on discussions on the KDB entry. This is based on the close linkage between the language and the database:

  1. Both KDB and KDB+ are developed in K
  2. Ksql and Q, the query languages for KDB and KDB+, respectively, are written in K.
  3. With a few minor exceptions in academia no, the K language is always used in conjunction with KDB.

Abcarter 23:12, 24 November 2006 (UTC)Reply

Merged the KDB (database) and did a very rough clean up. I deleted anything that was more marketing than factual. I'm embarrassed to say that there is really very little left as a result. I will expand on this in the next couple of weeks. Abcarter 01:48, 29 November 2006 (UTC)Reply

Comments on changes

edit

I'll be making numerous changes to the K entry in the next few weeks and using this section for comments when necessary. Abcarter 11:59, 29 November 2006 (UTC)Reply

Made some corrections to the infobox.

  1. The Kx site lists 1993 as the year when k was first developed.
  2. KDB+ is not an implementation of k but an application built on top of it.
  3. k is written in c but its design is not influenced by c in any obvious way.
  4. Apparently Scheme was the specific dialect of Lisp that influenced Arthur Whitney in the design of k

Abcarter 11:59, 29 November 2006 (UTC)Reply

65.254.63.193

edit

Your remarks on performance characteristics is great stuff. I'm not too sure if I follow it completely, any change of providing a source that one could read for more detail? Also, do you have any objective sources giving performance benchmarks or numbers? Abcarter 00:42, 1 December 2006 (UTC)Reply

Hello World Program

edit

After thinking about it I've reverting the deletion concerning the Hello World program. The wikipedia definition of such programs is:

A "hello world" program is a software program that prints out "Hello world!" on a display device.

Interpreted languages such as k can do this in a trivial way. Look at the list of Hello World programs and you'll see a number of similar languages with the same trivial example. While the example is trivial the point being made is not, the interpreted nature of k is a distinctive feature of the language and one of the first things you should know about it. Abcarter Talk 14:53, 3 January 2007 (UTC)Reply

This is nothing to do with the interpreted nature of the language; it would be trivial to design a language that had an identical "Hello World" program but compiled down to machine code. It is, however, illustrative of K's concise syntax. 81.86.133.45 18:47, 6 September 2007 (UTC)Reply
In K every statement is evaluated and the results immediately displayed. Literal values, like strings, evaluate to themselves. Consequently, you can argue that a Hello world program can just be the string, "Hello world!". While this feature of K facilitates an expressive and concise syntax, but it really isn't illustrative of it. A B Carter (talk) 04:16, 7 September 2007 (UTC)Reply

Performance Characteristics

edit

I'm not sure if I understand some of this paragraph:

>> The performance of modern CPUs is improving at a much faster rate than their memory subsystems.

Check. Memory is comparatively slow.

>> The small size of the interpreter and compact syntax of the language makes it possible for K applications to fit entirely within the level 1 cache of the processor.

Check. Smaller is better, but it would be nice to know exactly what a level 1 cache, and exactly what processor.

  1. Leveal 1 cache is the smallest memory cache in modern processors and therefore the fastest. The point is that the K executable is so small that it can stay resident in the L1 cache.

>> Vector processing makes efficient use of the cache row fetching mechanism and posted writes without introducing bubbles into the pipeline by creating a dependency between consecutive instructions.

Suppose I have an array expression like D = A + 3*(B+C) and I apply the classic do loop treatment of this statement, i.e. D[i] = A[i] + 3*(B[i]+C[i]), factors which would degrade the speed as array length increases would be the locality of access and cache utilsation (i.e. individual vectors are farther than the cache apart).

But K is an interpreter and is more likely to do something like D = 3*(B+C) then D = A + D, assuming A does not promote the type of D. But even if D, B, and C fit in the cache window for part 1 and A and D fit in part 2, would this really present such a speedup opportunity?

  1. Yeah, can't help you here. Hell, I don't even know what a pipeline "bubble" is.

This pipeline bubble thing is explained nicely in at least two places - have a look at Jim Blinn's book, Notation, Notation, Notation, Chapter 7, pp. 107-121. I often see it in Borders. Although the article is nearly 10 years old and he's writing about MMX, I imagine this problem is not unique to Intel hardware. Also, Intel has some nice code tuning tools and documentation on their web site. I imagine the average Kdb user does not use this hardware.Cowznofski 21:52, 28 January 2007 (UTC)Reply

>> These characteristics, combined with a highly optimized implementation, tend to make interpreted K programs significantly faster than hand-coded C/C++.

I would be more inclined to belived that well-coded K programs would tend to run significantly faster than their poorly-coded C/C++ counterparts.

  1. Even though I agree with the sentiment of this statement, it has all sorts of problems. The defensible claim is that the first version of a C program will often run slower that the first version of a K program that performs the same task. The C program isn't necessarily poorly-coded, just not optimized. While I believe this to be true, there is no cited source to back this up and obviously has NPOV issues.

I've never been particularly happy with this section. It was entered anonymously as a single edit. I asked for a citation and additional information (see above), but there was never a response. Still it's an valid topic. K is incredibly fast and it would be nice to have a clear and extended explanation for this. A B Carter (talk) 16:27, 25 January 2007 (UTC)Reply

PS - Please remember to sign your name with ~~~~ :). A B Carter (talk) 16:29, 25 January 2007 (UTC)Reply

Sorry... Cowznofski 21:31, 28 January 2007 (UTC)Reply

So for instance, if I use longer variable and function names in my C program, I can expect to exceed the L1 cache and get slower behavior? What insipid crock!!!24.85.131.247 (talk) 17:18, 29 September 2011 (UTC)Reply

first prototype J interpreter

edit

This might give some insight as to how Arthur Whitney thinks and why K is so fast. Arthur's first prototype J interpreter

  typedef char C;typedef long I; 
  typedef struct a{I t,r,d[3],p[2];}*A; 
  #define P printf 
  #define R return 
  #define V1(f) A f(w)A w; 
  #define V2(f) A f(a,w)A a,w; 
  #define DO(n,x) {I i=0,_n=(n);for(;i<_n;++i){x;}} 
  I *ma(n){R(I*)malloc(n*4);}mv(d,s,n)I *d,*s;{DO(n,d[i]=s[i]);} 
  tr(r,d)I *d;{I z=1;DO(r,z=z*d[i]);R z;} 
  A ga(t,r,d)I *d;{A z=(A)ma(5+tr(r,d));z->t=t,z->r=r,mv(z->d,d,r);R z;} 
  V1(iota){I n=*w->p;A z=ga(0,1,&n);DO(n,z->p[i]=i);R z;} 
  V2(plus){I r=w->r,*d=w->d,n=tr(r,d);A z=ga(0,r,d); 
  DO(n,z->p[i]=a->p[i]+w->p[i]);R z;} 
  V2(from){I r=w->r-1,*d=w->d+1,n=tr(r,d); 
  A z=ga(w->t,r,d);mv(z->p,w->p+(n**a->p),n);R z;} 
  V1(box){A z=ga(1,0,0);*z->p=(I)w;R z;} 
  V2(cat){I an=tr(a->r,a->d),wn=tr(w->r,w->d),n=an+wn; 
  A z=ga(w->t,1,&n);mv(z->p,a->p,an);mv(z->p+an,w->p,wn);R z;} 
  V2(find){} 
  V2(rsh){I r=a->r?*a->d:1,n=tr(r,a->p),wn=tr(w->r,w->d); 
  A z=ga(w->t,r,a->p);mv(z->p,w->p,wn=n>wn?wn:n); 
  if(n-=wn)mv(z->p+wn,z->p,n);R z;} 
  V1(sha){A z=ga(0,1,&w->r);mv(z->p,w->d,w->r);R z;} 
  V1(id){R w;}V1(size){A z=ga(0,0,0);*z->p=w->r?*w->d:1;R z;} 
  pi(i){P("%d ",i);}nl(){P("\n");} 
  pr(w)A w;{I r=w->r,*d=w->d,n=tr(r,d);DO(r,pi(d[i]));nl(); 
  if(w->t)DO(n,P("< ");pr(w->p[i]))else DO(n,pi(w->p[i]));nl();} 
  C vt[]="+{~<#,"; 
  A(*vd[])()={0,plus,from,find,0,rsh,cat}, 
  (*vm[])()={0,id,size,iota,box,sha,0}; 
  I st[26]; qp(a){R a>='a'&&a<='z';}qv(a){R a<'a';} 
  A ex(e)I *e;{I a=*e; 
  if(qp(a)){if(e[1]=='=')R st[a-'a']=ex(e+2);a= st[ a-'a'];} 
  R qv(a)?(*vm[a])(ex(e+1)):e[1]?(*vd[e[1]])(a,ex(e+2)):(A)a;} 
  noun(c){A z;if(c<'0'||c>'9')R 0;z=ga(0,0,0);*z->p=c-'0';R z;}  
  verb(c){I i=0;for(;vt[i];)if(vt[i++]==c)R i;R 0;} 
  I *wd(s)C *s;{I a,n=strlen(s),*e=ma(n+1);C c; 
  DO(n,e[i]=(a=noun(c=s[i]))?a:(a=verb(c))?a:c);e[n]=0;R e;} 
  main(){C s[99];while(gets(s))pr(ex(wd(s)));}

Personally, I like this style. Tradition goes out the window, where it belongs. My eyes don't have to wander too far, nor do I have to turn any pages, to find something.193.8.106.71 14:09, 9 February 2007 (UTC)Reply

malloc() and no free()? No wonder it's fast. Monadic Mike 21:11, 27 June 2007 (UTC)Reply

Ouchie. 69.255.27.90 (talk) 00:49, 14 July 2010 (UTC)Reply

My eyes hurt from looking at this. Dtm1234 (talk) 14:19, 28 June 2012 (UTC)Reply

K3, K4 and Q

edit

This desperately needs to be forked into "k3" (historical interest only) and "k4" (actually useful) articles, especially since a personal version of q is now available free (as in beer) i'm capable of porting all the k3 code here to k4, it's not that hard and i'm quite familiar with both, but i'm not sure what the "wiki way" is to do a major change like this--do i just change this into the k4 article and create a k3 stub saying "obsolete functional language from Kx"? Adavies42 (talk) 18:35, 22 August 2008 (UTC)Reply

I've moved this comment to a separate section so that the discussion can focus on the more general issue of the boundaries of the present article.

Two quick comments. First, K version 4 is not significantly different from K version 3 in terms general syntax and semantics. I'm not too sure there is anything in the present article that needs to be changed in this regard. Second, I assume you are actually talking about q, a new language that is written in the k language. Take a look at the q.k script and you'll see how q is defined in terms of the underlying k language. There is already a short article on Q and presumably your efforts should be devoted to that article. A B Carter (talk) 16:23, 25 August 2008 (UTC)Reply

um, yes and no. there are big chunks of k3 that were dropped completely (all the gui stuff), chunks that were changed drastically (i/o), and the merger with the database layer. (kdb/ksql was a completely separate software package, a set of k3 scripts that implemented the db; kdb+ is built into the q interpreter and the q.k language implementation.) second, k4 is still of some interest; if nothing else, some k4 knowledge is generally picked up by q programmers, and it's helpful when debugging q, as all the error messages are in k. but yes, you're right that the main effort should be devoted to the q article. Adavies42 (talk) 03:45, 19 September 2008 (UTC)Reply

Untitled

edit

k vs. kdb

this article is more a product placement of kx/kdb+ than explanation of k. The reference to the free k-language implementation is missing (https://github.com/kevinlawler/kona/wiki/Group) and it is focusing to much on kdb+ the database which is finally based on q which is based on k. So there is only a second level link to k. — Preceding unsigned comment added by 78.53.59.35 (talk) 09:27, 12 May 2013 (UTC)Reply

Code samples do not appear to work

edit

I attempted to run the code samples provided on this page using the KDB, which includes a k4 interpreter, and of all the samples only "x@>#:'x" actually ran without errors. For example:

q)k)2!!7!4

'type — Preceding unsigned comment added by 208.100.48.30 (talk) 20:31, 11 February 2014 (UTC)Reply

q syntax highlighting lost

edit

Since the switch from Geshi to Pygments for syntax highlighting (phab:T85794), support for 'q' was unfortunately dropped, as can be seen with the plain text formatting on this page. Are there other pages using this syntax? If we want 'q' syntax highlight support again, it will need to be added to Pygments. However, Pygments does include support for 'apl', which may be a suitable fallback, and it can be very easily added like this patch. John Vandenberg (chat) 03:44, 13 July 2015 (UTC)Reply