<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://openjournal.wiki/index.php?action=history&amp;feed=atom&amp;title=User%3AProfessorlamp%2F10_minutes_with_K</id>
	<title>User:Professorlamp/10 minutes with K - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openjournal.wiki/index.php?action=history&amp;feed=atom&amp;title=User%3AProfessorlamp%2F10_minutes_with_K"/>
	<link rel="alternate" type="text/html" href="https://openjournal.wiki/index.php?title=User:Professorlamp/10_minutes_with_K&amp;action=history"/>
	<updated>2026-09-11T12:42:05Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.9</generator>
	<entry>
		<id>https://openjournal.wiki/index.php?title=User:Professorlamp/10_minutes_with_K&amp;diff=57&amp;oldid=prev</id>
		<title>Professorlamp: Created page with &quot;= What is K/Kona? = K is an array programming language much like J, APL, A and others. Kona is the open source equivalent of this, Kona strives to be a truthful representation of K rather than an extension or competitor.  From now on I’ll be talking about Kona, but all the examples that work in Kona, also work in K.  On to the code!  == A whirlwind tour == Nearly everything in Kona is an array. Let’s define a variable &lt;code&gt;numbers&lt;/code&gt; that holds the numbers 0 thr...&quot;</title>
		<link rel="alternate" type="text/html" href="https://openjournal.wiki/index.php?title=User:Professorlamp/10_minutes_with_K&amp;diff=57&amp;oldid=prev"/>
		<updated>2026-09-11T09:47:26Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;= What is K/Kona? = K is an array programming language much like J, APL, A and others. Kona is the open source equivalent of this, Kona strives to be a truthful representation of K rather than an extension or competitor.  From now on I’ll be talking about Kona, but all the examples that work in Kona, also work in K.  On to the code!  == A whirlwind tour == Nearly everything in Kona is an array. Let’s define a variable &amp;lt;code&amp;gt;numbers&amp;lt;/code&amp;gt; that holds the numbers 0 thr...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= What is K/Kona? =&lt;br /&gt;
K is an array programming language much like J, APL, A and others. Kona is the open source equivalent of this, Kona strives to be a truthful representation of K rather than an extension or competitor.&lt;br /&gt;
&lt;br /&gt;
From now on I’ll be talking about Kona, but all the examples that work in Kona, also work in K.&lt;br /&gt;
&lt;br /&gt;
On to the code!&lt;br /&gt;
&lt;br /&gt;
== A whirlwind tour ==&lt;br /&gt;
Nearly everything in Kona is an array. Let’s define a variable &amp;lt;code&amp;gt;numbers&amp;lt;/code&amp;gt; that holds the numbers 0 through 9&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;numbers: 0 1 2 3 4 5 6 7 8 9&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is a quicker way with the monadic(takes one argument) enumerate(!) function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;numbers: !10&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let’s reverse that list&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;|numbers&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;9 8 7 6 5 4 3 2 1 0&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;|!10&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;9 8 7 6 5 4 3 2 1 0&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Most functions change their meaning depending on the amount of arguments given. For instance, that enumerate function above is a modulus operator when given two arguments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;5 ! 2&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Most functions are monadic and dyadic, i.e. they can take 1 or 2 arguments, but some can take up to 4 different arguments. It can actually get even more complex, some functions operate differently depending on if their arguments are atoms or lists.)&lt;br /&gt;
&lt;br /&gt;
Let’s take our first steps to programmerhood&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;greeting: &amp;quot;Hello, world!&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
How long is this string?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;#greeting&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
` 13`&lt;br /&gt;
&lt;br /&gt;
What’s the first letter?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;greeting[0]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
` “H”`&lt;br /&gt;
&lt;br /&gt;
Or the more idiomatic ‘K’ way, using the ‘first’ monadic function&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;*greeting&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
` “H”`&lt;br /&gt;
&lt;br /&gt;
What’s the last letter?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;*|greeting&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;quot;!&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Read that as, take the first(*) letter from the reversed(|) string.&lt;br /&gt;
&lt;br /&gt;
Hide dupes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;? greeting&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;quot;Helo, wrd!&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More index trickery&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;greeting[7 8 7]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;quot;wow&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That gets the 7th index of the string, then the 8th, and then the 7th again.&lt;br /&gt;
&lt;br /&gt;
Let’s generate some random numbers. How about 20 numbers in the range 0-99?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;random: 20 ? 100&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;random&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
` 30 25 69 86 66 79 47 96 52 21 31 54 96 89 22 76 91 36 78 70`&lt;br /&gt;
&lt;br /&gt;
Which ones are greater than 50?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;random &amp;gt; 50&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
` 0 0 1 1 1 1 0 1 1 0 0 1 1 1 0 1 1 0 1 1`&lt;br /&gt;
&lt;br /&gt;
Hmm, that’s not very helpful… I need the indices of those.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;amp; random &amp;gt; 50&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;3 4 5 7 8 11 12 13 15 16 18 19&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Nice, now I can finally get them!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;random[&amp;amp; random &amp;gt; 50]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;69 86 66 79 96 52 54 96 89 76 91 78 70&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hmm, too many, I only need 5&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;5 # random[&amp;amp; random &amp;gt; 50]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;69 86 66 79 96&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Much better.&lt;br /&gt;
&lt;br /&gt;
Let’s take a step back and breathe… Done? Okay&lt;br /&gt;
&lt;br /&gt;
Dictionaries:&lt;br /&gt;
 &amp;lt;code&amp;gt;dict[`a]: &amp;quot;shake&amp;quot;&lt;br /&gt;
 dict[`b]: &amp;quot;your&amp;quot;&lt;br /&gt;
 dict[`c]: &amp;quot;booty&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 dict[`a `a `a]&lt;br /&gt;
   (&amp;quot;shake&amp;quot;&lt;br /&gt;
   &amp;quot;shake&amp;quot;&lt;br /&gt;
   &amp;quot;shake&amp;quot;)&lt;br /&gt;
 dict[`a `a `a]&lt;br /&gt;
   (&amp;quot;shake&amp;quot;&lt;br /&gt;
   &amp;quot;shake&amp;quot;&lt;br /&gt;
   &amp;quot;shake&amp;quot;)&lt;br /&gt;
 dict[`a `b `c]&lt;br /&gt;
   (&amp;quot;shake&amp;quot;&lt;br /&gt;
   &amp;quot;your&amp;quot;&lt;br /&gt;
   &amp;quot;booty&amp;quot;)&lt;br /&gt;
 dict[`a `b `c]&lt;br /&gt;
   (&amp;quot;shake&amp;quot;&lt;br /&gt;
   &amp;quot;your&amp;quot;&lt;br /&gt;
   &amp;quot;booty&amp;quot;)&amp;lt;/code&amp;gt;&lt;br /&gt;
Functions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;addOne: {x + 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;addOne 6&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;7&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With multiple arguments:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;addBoth: {[x;y] x + y}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;addBoth[5;6]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;11&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Works on lists too&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;addBoth[5 12; 2 2]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;7 14&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More addition:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;5 + 5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;10&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;5 + 10 20 30&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;15 25 35&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;5 6 7 + 10 20 30&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;15 26 37&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let’s do some Euler (spoilers ahead for problem 1).&amp;lt;blockquote&amp;gt;If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.&amp;lt;/blockquote&amp;gt;Gather the numbers&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;n: !1000&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Which ones are multiples of 5?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;n[&amp;amp; (n!5) = 0]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
How about 3?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;n[&amp;amp; (n!3) = 0]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;n[&amp;amp; ((n!3) = 0) | ((n!5) = 0)]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Store it&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;multiples: n[&amp;amp; ((n!3) = 0) | ((n!5) = 0)]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sum it&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;+/ multiples&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Voila&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;multiples&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
233168&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
Looking past the terse syntax of Kona, I find it to be amazingly expressive and makes me think much more about the actual problem at hand.&lt;br /&gt;
&lt;br /&gt;
Everything is composable and polymorphic, it all ‘just works’.&lt;br /&gt;
&lt;br /&gt;
If you want to get started writing in Kona, then head over to the Github page and clone the repo.&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
The best documentation I’ve found for K/Kona is the K User and Reference Manual. They’re very well written and thoroughly documented.&lt;br /&gt;
&lt;br /&gt;
K user manual https://web.archive.org/web/20041022042401/http://www.kx.com/technical/documents/kusrlite.pdf&lt;br /&gt;
&lt;br /&gt;
K reference manual https://web.archive.org/web/20050111142057/http://www.kx.com/technical/documents/kreflite.pdf&lt;br /&gt;
&lt;br /&gt;
There’s also Kona’s wiki for a more casual read https://github.com/kevinlawler/kona/wiki&lt;/div&gt;</summary>
		<author><name>Professorlamp</name></author>
	</entry>
</feed>