oK

oK is an interpreter for a dialect of the K programming language, modeled after the experimental k5/k6 interpreters which were never released to the public. You can try it out using three different web-based frontends:

oK REPL

The web REPL features a few special commands which can be issued at the beginning of a line:

oK provides several numbered IO verbs:

dyadic 0: takes a symbol or string as its left argument and writes the right argument to that destination as text. The right argument can be a symbol, a string, or a list of symbols or strings. The symbol is ignored and output is always sent to the console. This behavior is designed to be compatible with other K interpreters which use the symbol to indicate an output file.

monadic 0: reads the content of URL. It takes a string as its right argument and performs a synchronous HTTP request to that URL. The result will be a tuple containing the HTTP status code followed by the response, if any. You can use this in conjunction with pastebins to load code from elsewhere or access RESTful web APIs. Note that most web browsers restrict cross-site HTTP requests from javascript under the same-origin policy- you'll need a server which responds with an Access-Control-Allow-Origin header.

monadic 1: works just like monadic 0: except it expects the response to be JSON rather than arbitrary text, and it attempts to parse it into a K data structure you can then manipulate:

  url:"http://api.openweathermap.org/data/2.5/weather?q=London,uk"
"http://api.openweathermap.org/data/2.5/weather?q=London,uk"
  t:1:url
(200;[coord:[lon:-0.13;lat:51.51];sys:[type:1;id:5091;message:0.0224;country:"GB"
sunrise:1425709902;sunset:1425750674];weather:,[id:800;main:"Clear";description:"Sky is Clear"
icon:"01d"];base:"cmc stations";main:[temp:288.11;pressure:1024;humidity:44;temp_min:286.85
temp_max:289.82];wind:[speed:6.2;deg:230];clouds:[all:0];dt:1425736003;id:2643743;name:"London";cod:200])
  t[1;`weather;0;`description]
"Sky is Clear"

monadic 5: returns a printable string representation of the right argument, as in K3. Sometimes this can be useful for debugging:

  5: 1 2 3
"1 2 3"
  5:"foo"
"\"foo\""
  5: {x+2*y}
"{[x;y]x+2*y}"

oK Mobile

Tilting your device horizontally will provide a QWERTY touch-keyboard, and a vertical orientation will provide a calculator-like keypad which provides access to all K verbs and adverbs with a single keypress. Tapping on items from the output history copies them to your edit buffer.

oK mobile provides graphing functionality in the form of the built-in pl (plot line) and ps (plot scatter) functions. Both will automatically rescale to suit the data you provide. The first argument to each function specifies the domain (x axis) and can be a list of numbers or a single number n (interpreted as !n). The second argument specifies the range (y axis) and can be a list of numbers or a monadic function f (interpreted as f'x).

oK mobile supports the 0: verb for reading from (monadically) or writing to (dyadically) browser-local storage. If the left argument is an empty symbol, output will be printed to the console, as with most K interpreters. Symbols and strings are interchangeable as 0: sources/destinations. Monadic 5: produces a printable string representation of its right argument.

The dyadic 6: verb permits creating custom user menus. The left argument must be a string, which will be used as a title for the menu. The right argument may be either a list or a dictionary of monadic/niladic functions. If the right argument is a list, the menu will contain a button for each list item, and clicking the button will append that button's contents to the edit line. If the right argument is a dictionary, buttons will be created for each key and clicking the button will execute the associated monad/nilad. If the nilad returns a string, it will be appended to the edit line. Consider a few examples:

"simple"  6: ("foo";`bar;`baz);
"my menu" 6: `a`b!({`0:"pressed A";0};{`0:"pressed ",x;0});
"another" 6: `a`b!({`0:"pressed A";0};{"append this"});

The dyadic 1: verb permits asynchronously loading the contents of a document as a string via an HTTP GET. The right argument must be a URL as a string. If the left argument is a symbol, the result of the call will be stashed in a variable with the corresponding name when the result comes in. If the left argument is a monad, it will be evaluated as a callback with the result when it comes in. The dyadic 2: verb permits asynchronously storing a string via an HTTP POST. The left argument must be a URL as a string. The right argument should be the value to write as a string. These mechanisms makes it possible to load or store serialized environments or boot scripts from external storage. Browser security constraints require that the remote server provide a Access-Control-Allow-Origin header, which is unfortunately not the case with most pastebin services.

If you store a K string in a local storage variable named boot, it will be executed when oK mobile starts up. Similarly, if you store a dictionary in a local storage variable named env it will replace the default environment at startup. Either of these mechanisms may be used to stash your favorite utility functions or frequently used data. Recall that .{} can be used at the base level to retrieve a reference to the root environment, so "env" 0: .{} is one way to back up your entire workspace. Setting either boot or env to the empty list () will stub it out and prevent it from being used at startup.

oK mobile supports a basic set of backslash commands:

iKe

iKe is an experimental programming environment built on oK. It allows you to rapidly write event-driven graphical programs in K.

The interface consists of an editor pane on the left with a status bar and display on the right. Pressing shift+enter in the editor will compile and run the K program. Escape will halt a running program. Pressing shift+enter with a section of text selected will execute just that snippet and display the results, allowing quick experimentation and sanity checking. For more details, see the iKe manual.

Resources


back