The below examples can be run in the browser by clicking on the link. This opens the web-based Kap interpreter with the code shown in the entry field. Simply click on “Send” to run the code.
Numbers
Displaying a large power of 2
This example demonstrates the support for bigints. We simply take 2 to the power of 300:
Division of integers giving rational results
If you divide two integers, the result is a rational number. This example creates an array of numbers from 1 to 10 (1+⍳10) and divides 2 by each element in the array.
The Kap interpreter provides three different ways to display rational numbers. The display mode is chosen using the ]radmode command (interpreter commands are prefixed by the ] symbol). Try using the different arguments normal, fancy or decimal to try them.
Graphics
Draw a circle generated from complex numbers
This example creates a 2-dimensional array of complex numbers, with the horizontal axis representing real numbers between -20 and 20, and the vertical axis representing complex numbers -20i and 20i, and each vaue in the array being the result of the sum of these numbers
Then the absolute value (using the function |) is used to get the length of the vector and this value is then compared with 20 in order to get a binary array where the value is 1 where the length is greater than 20 and 0 where it’s less than 20. Drawing this array results in a rather low resolution circle on the screen.
Animated graphics
While the current implementation of graphics support in Kap is limited, one can still do basic animation with it. Press “Stop” to stop the animation.
Game of life
Charting
Display a line chart of a 2-dimensional array
The function ⍴ is used to reshape an array fo 10 numbers into a 2-by-5 array. This array is then passed to the function chart:line which draws a line chart. You can also experiment with using the alternative charting functions: chart:bar and chart:pie.
Simulate die rolls
Roll 6 6-sided dice 10000 times and do a histogram plot of the results.
Sound
Playing sounds
The function audio:play accepts a sample in the form of an array of values between -1.0 and 1.0. The sample is played at 48 kHz.
Games
Play 2048
Below is a simple implementation of the game 2048. Use the commands u, d, l or r for up, down, left or right respectively.
.png)

