
A raytracer in 7 lines of 'K' - jacquesm
http://www.nsl.com/k/ray/raya.k
======
tlack
Will one of you geniuses hurry up and write an open source K interpreter? It's
not that complex of a language to parse..

~~~
jasonwatkinspdx
The source to Mr Whitney's prior language, A+, is available.

~~~
tlack
Unfortunately the source is rather poorly coded - it's Arthur's "K in every
language" style of C - and A+ has a lot of assumptions that I'm not
comfortable with. I'd love a modernized K interpreter suitable for use by
stylish gentlemen. Which perhaps could be the name..

------
tlack
If anyone is interested in learning more about K and Q, the best tutorial I
found came from a third party - <http://gbkr.com/subjects/q/index.html>

------
tybris
OK, this is a mess. Lets try to get some new coolness metrics here.

A. Number of lines of assembler it compiles to

B. Time it took you to write it (no cheating)

C. Number of symbols used (with names being one symbol)

~~~
huntse
K is an interpreted language.

~~~
Locke1689
Then it's JIT interpreted to object code.

------
mrcharles
You know, 7 lines or not, name your goddamned variables. I'd fire someone who
presented me with code like this.

~~~
personamb
I worked at a K shop last summer, and when I was learning the language, I
tried using sensible variable names. I was told in no uncertain terms that,
when you write K, local variables should be one letter, globals should be two,
and functions should be three.

It sounds like a total disaster, but after about two weeks (which is a long-
ass time to learn a language), everything made perfect sense, and I really
enjoyed using it for the rest of the time. It's very powerful and fast to
execute, and after you get the hang of it, it's fast to write, too.

~~~
gruseom
Do tell us more about your experience. I'm fascinated with this stuff from
afar.

Also, I'm curious how their database stacks up: what's it better/worse at? It
seems like magic for a program so small to do so much so well. I'd like to
know what the tradeoffs are. (Either that or move to their universe.)

~~~
personamb
Sorta forgot about this thread, but hopefully ou see this.

K is super-great at vector operations; element-wise addition between two lists
of equal length, for example; more powerfully, mapping lists to functions.

The DB stuff we were doing were columnar databases, so it was incredibly fast
at doing data analysis and correlations. Not so fast at adding single rows,
but if you wanted to take a list of transactions and compare things day-over-
day, or do sophisticated statistical operations, you simply had to write a
line or two, and watch it take multiple million-element lists and give you an
answer in milliseconds. I'm still pretty convinced it was voodoo magic.

When I used it, there was a pretty hefty license fee, but there's a trial
version which limits the amount of memory it will use, but can still do quite
a bit to give you a sense of the speed (as long as you're doing it right).
Remember, no stinkin' loops!

~~~
gruseom
_I'm still pretty convinced it was voodoo magic._

I was kind of afraid you would say that. I wish they'd open-source it.

It's such a pity that Peter Seibel didn't include Arthur Whitney in _Coders at
Work_. I suggested him, IIRC, but he didn't get in. As far as I'm concerned he
belongs in the top echelon. Here is what Roger Hui, the J guy and no slouch,
said (I love this story):

 _Someone once asked Peggy Lee who she thought was the best jazz singer. Her
answer was, You mean besides Ella? Likewise, the answer to the question Who's
the best programmer? is Besides Arthur?_

Edit: maybe if I'd included that in my suggestion to Seibel it would have
helped :)

------
Sandman
As far as readability goes, this might have as well been written in machine
language.

~~~
gruseom
Except that a machine language program would be thousands if not millions of
times as long.

Readability is relative. Java is unreadable to my grandmother. Turkish is
unreadable to me. In other words, the opinion of someone who hasn't learned a
language regarding its readability is irrelevant.

It is true that the way you read a language like this is different from the
way you read Java. You don't expect to grok a line of code atomically, then
move to the next line. It's more like reading math: you _work_ with each line,
understanding what makes it tick. No doubt that doesn't appeal to everyone.
But the APL/K/J people do amazing things.

The ultimate answer as to whether or not this is just line noise?
<http://kx.com/Customers/end-user-customers.php>

~~~
jacquesm
> Readability is relative. Java is unreadable to my grandmother. Turkish is
> unreadable to me. In other words, the opinion of someone who hasn't learned
> a language regarding its readability is irrelevant.

What a gem!

I should start a collection of those, every now and then you get these things
you can just frame and look at three times a day here.

~~~
gruseom
I'm just glad somebody got my point. It seems so obvious, yet it must not be,
because the contrary is much more common. It especially bears repeating in the
context of a largely undiscovered gem like K.

------
trezor
Voted up in hope that someone can adequately explain that piece of code
frighteningly close to line-noise.

~~~
gruseom
_frighteningly close to line-noise_

That's everyone's initial reaction (it was mine too). But my experience has
been that if you suspend initial disbelief and approach the language on its
own terms, the result is jaw-dropping awe.

<http://news.ycombinator.com/item?id=266167>

