Giter VIP home page Giter VIP logo

kona's Introduction

Kona

What is Kona?

Kona is the open-source implementation of the k3 programming language. k is a synthesis of APL and LISP. Although many of the capabilities come from APL, the fundamental data construct is quite different. In APL the construct is a multi-dimensional matrix-like array, where the dimension of the array can range from 0 to some maximum (often 9). In k, like LISP, the fundamental data construct is a list. Also, like LISP, the k language is ASCII-based, so you don't need a special keyboard.

For many people, k was the preferred APL dialect. When it was available, it tended to be popular with investment bankers, the performance obsessed, and analysts dealing with lots of data. It is a demanding language.

k was originally designed by Arthur Whitney and Kx Systems. Praise for k should be taken to refer to Kx's k. Kx sells a popular database called KDB+. People can and do create networked trading platforms in hours. If your business needs production support, you can evaluate KDB+ prior to purchasing from Kx, or possibly speak with Kx consulting partner First Derivatives. The 32-bit version of KDB+ is available for free.

Kx's KDB+ uses the Q language, and is built on top of k4. Kx used to sell a database called KDB, which used the KSQL language, and was built on top of k3. Earlier, Kx sold k2 as its primary product. Before k2, UBS had a 5-year exclusive license to k1. To the confusion of all, these terms are used interchangeably. Kx's k3, k2 and k1 are basically no longer available. While you get k4 with KDB+, k4 is proprietary to Kx and no documentation is available. Kona is a reimplementation that targets k3 (which stopped being available about 20 years ago). Kona is unaffiliated with Kx.

To get perspective on the various incarnations see https://ngn.bitbucket.io/k.html

A note on the unusual style of C code: It attempts to replicate the style of Arthur Whitney. A striking original example is contained in file https://github.com/tavmem/buddy/blob/master/a/b.c. There are 2 versions of the buddy memory allocation system. The first is in 11 lines written by Whitney. The second is in well documented traditional C (almost 750 lines).

Mailing Lists

kona-user is about using the Kona programming language.

kona-dev is about developing the Kona language itself.

Installation

Windows

You can find an executable version of Kona here. Download k.exe. Use Windows "Explorer" to move k.exe from the "Download" directory to another directory ... or not. Double click on k.exe in "Explorer" to start a Kona session. Alternatively, start a "cmd" console window, navigate to the directory containing k.exe, and key in "k".

macOS

If you have Homebrew installed, you can install Kona using brew:

brew install kona

Build from source

For macOS, Linux, BSD, Cygwin and Android: Navigate to the directory you want to install Kona, then type:

git clone https://github.com/kevinlawler/kona.git
cd kona
make                                #gmake on BSD

Then, while in the "kona" directory, run:

./k                      #./k_test to run the test suite

Android builds are similar, but you must set use this command when running make:

make OS=android

For Windows: Pretty much the same process, but you will need MinGW-w64 (Mingw-builds project package), and you will need MSYS (or MSYS2) for bash. You can start up Kona from MSYS, or from a native Windows "cmd" session. In MSYS, type "./k" or just type "k" when in the "kona" directory. When in "cmd" just type "k" as "./k" won't work. You can also double-click on k.exe from Windows Explorer.

Input Issues

If you experience input issues with the command-line interpreter, such as visible arrow keys, try the rlwrap utility and see if it solves your problem.

Further Information

You can find further information about Kona at the wiki.

kona's People

Contributors

0branch avatar alesya-h avatar bakul avatar crestwave avatar dlorean00004 avatar fenollp avatar ibara avatar isawdrones avatar joebo avatar johnearnest avatar kevinlawler avatar nikkicoon avatar nsmaciej avatar oskmeister avatar paul7 avatar promovicz avatar refi64 avatar seekingmeaning avatar silentbicycle avatar slenkjon avatar sofuture avatar tangentstorm avatar tavmem avatar thyrgle avatar tomducoin avatar waldyrious avatar xtian avatar zachwick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kona's Issues

multithreaded execution

Build in multithreading

What's the right way to go about this? Do objects need mutexes? Should the main loop process queries in parallel? Should multiple threads run only within a given verb (eg four threads splitting the computation of a single plus application that wait on each other to complete), or should threads be able to run ahead (eg thread 1 starts negating its section while waiting for 2-4 to finish adding), or some other scheme?

' ': crash/signal

segfault

'1 2 3
':1 2 3

either add some form of NYI or implement ' and 'x signal (what would ':x be?)

Feature: proper subfunctions

Subfunctions are missing certain obvious and expected functionality. In particular, they don't inherit the namespace of the parent function.

{a:10; {x,a}x} 1

(1;) /expected 1 10

a:10

{1+{a}0}0

11 /OK

{{.k.a}0}0

10 /OK

This will require fairly deep understanding of the function type-7 datatype. It will require changing how the function data structures are built, but it won't require modifications to how the parser or main execution loop work, so it should be easier than the feature 'early return for functions'.

Notes from the codebase:
proper sub-functions (hint is the non-null f passed to wd_(). Inherit/copy active dict to kV()[LOCAL] )
Arthur: "subfunctions are just projections, eg c:{[f;g]{f g x}} composition d:{[f;g]{[f;g;x]f g x}[f;g]} composition c[-:;%:] 3 ; d[-:;%:] 3

crash: 3 3#!0

taking from empty lists should be equivalent to taking the corresponding type from the following atoms:
_n /0
0 /1
0.0 /2
" "
`

Implement the \d directory command

In c.c fill in the d command, so that you can navigate the K tree. This should update
S __d
in k.c, the value returned by _d .

.`      /show the entire k tree, a helpful command to know
_d    /show the symbol atom representing your current position on the tree
\d .   /should return you to the root of the k directory/dictionary
\d k  /relative, should drop you into the k subdirectory of the 
       /current directory/dictionary, creating if it doesn't exist
\d .k.a /absolute, should drop you directly into the .k.a node, creating if it doesn't exist

Feature: Dyadic form $ should execute char strings

when {} is the left arg, form executes the char atom or char string to the right. ."1+1" works, look there if you need a hint

  0$"27"
27
  0.0$"27"
27.0
  " "$"asdasd"
"asdasd"
  `$"sadasd"
`"sadasd
  {}$"1+1"
index error  /expected 2

crashes

Typing various things causes kona to crash, rather than provide a meaningful error. For example:

(|+\)

Collect a list of them here, add them to the test suite as they are fixed.

Feature: sorting for dictionaries

Update KC() ("K compare") to provide a sensible comparison function (results in {-1,0,1}) for dictionaries. This will let us sort dictionaries.

Feature: random seed command \r and \r [seed]

\r by itself should return the random seed. \r with an argument should set the random seed so that controlled experiments can be performed. There is a hook in c.c for \r. It may need to be modified. The random seed code is in k.c and mt.c

Multivalent each, over, and scan

Each, over, and scan all have forms like f/[a1;a2;a3;...]

f is any type_seven verb, function, etc.

The items in the argument list are either atoms or lists. Any items that are lists must be the same length. Let n be 1, or if lists are present as arguments, let n be the length of the lists.

For the each adverb, f'[a1;a2;...;ak] is the list of n items f[a1_i;a2_i;ak_i], where subscript i represents the ith item of the list, or in the case of the atom, the atom itself for any value i.

If any argument has length zero, then the result is the empty list ()

For the over adverb, f/[x0;a1;...;ak] is xn, so that

x1: f[x0;a1_1;...;ak_1]
x2: f[x1;a1_2;...;ak_2]
.
.
.
xn: f[xn-1;a1_n;...;ak_n]

if any argument has length 0, the result is x0

And similarly for scan f[x0;a1;...;ak] , with the result being (x0;x1;...;xn) --- if all arguments other than x0 are length 0, then the result is ,x0

step \s script command

Implement the \s step command. step should check for "script" and then "script.k" (see code in the \l command).

Step executes a script line by line. Lines should appear one by one in the console. Hit enter to execute the line, then enter again to load the next line. Backslash at any time causes the stepping to end.

circular references

There are no checks in place to stop circular references in K objects. Circular references are created when objects in the K tree contain a reference to themselves or to one of their ancestors. An ancestor is any object on the path from the root to the object.

Attempting to print objects with circular references results in an infinite loop. Printing should also be changed to return after a given depth.

One way to create a circular reference is to do something like
c: .`.k
while you are in the .k directory. This creates an entry inside .k that points back to .k.

Attempts to create a circular reference should result in a ref error. Any checks should be efficient. There are some comment in the code pointing out where modifications might be needed.

K3 had a couple global system variables that could have been involved in this process. The system variable _v held the symbol name of the variable being amended, whether by dot or by at. The variable _i held the indices where _v was being modified. Neither has been implemented. It isn't clear whether these are necessary to implement the check.

k should execute from the command-line without dropping into the repl

most languages (perl,php,ruby,...) have a command-line option for executing strings.

perl -e "print 1+1"
ruby -e "p 1+1"
php -r "echo 1+1;"

K should have this, and it should follow the most sensible convention. Let's decide on the character here (e? r? x? other?) first, please provide justification for your vote

4: dyadic "system get" `4:"ls" (and 3: system set)

When 4: is called with a left empty symbol argument (`) and a right char or charvector or sym argument, it should return the result of that string executed as a system command as a list of char vectors.

  `4:"ls"
("k.c",
 "l.c",
 "README"
)

Feature: 5: monadic, printed form

Also known as executable form. Basically, this verb turns data into printable strings. 5:monadic takes any argument x and returns a character vector containing the representation of x that would be printed to the console. (The idea behind calling it executable form is that you could repaste it into the interpreter and get the same x back.)

This function will look a lot like the showAtDepth function. A proper solution will refactor showAtDepth() to rely on the same code. This would be a great way to familiarize yourself with the codebase. The showAtDepth function will step you through most of the tricky parts, including representing functions.

5: 1 2 3

"1 2 3"

5: {x}

"{x}"

Goes in 0.c at K _5m(K x){ }

boolean over b f/ x

b is a boolean expression
f is a verb or function
x is the argument

apply f to x until b evaluates to exactly zero (and not tolerantly zero)

see the adverbs section in k.c

seamless make process

project does not make without say 'cp config.mk.linux config.mk'

is automake and ./configure the right way to go about this?

remove uses of C modulo %

There are a lot of places in the code that execute loops modulo the width of some data structure for the purposes of simultaneous handling lists and single element data atoms. Modulo is a slow operation because it has to compute a division. This slows the code down significantly. You can verify this by rewriting the implementation of the plus verb. Remove references to modulo and break the handling of lists and atoms into separate cases if necessary.

1 + 1 2 3
1 2 3 + 1 2 3

Both use the same loop dependent on mod and are slower as a result

// handles all four possibilites, but slow
else if(1==ABS(at) && 1==ABS(bt)) DO(zn,kI(z)[i]=kI(a)[i%an]+kI(b)[i%bn])

//handles just the vector + vector case (untested)
else if (-1==at && -1==bt) DO(zn,kI(z)[i]=kI(a)[i]+kI(b)[i])

//handles just the vector + vector case (using vector operations)
else if(-1==    at  && -1==    bt ) { veci *c=(veci*)a,*d=(veci*)b,*e=(veci*)z; DO(((((zn+3)+1)&~1))/2, e[i]=c[i]+d[i] ) if(z!=b)z->c=1; z->t=zt; z->n=zn; } 

Feature: Print Precision command \p and \p [digits]

Implement the print precision command. The global PP variable (default 7) specifies to how many decimal points floats can be displayed (and rounded for the purposes of display). When no argument is given the current precision should be returned as an integer atom. The suggested valid range for arguments is 0-19, but that might not be correct. The argument '0' is supposed to be a special case that prints at the maximum/full precision, this will require a few small changes to the codebase, grep for PP. Print precision should also affect the format functions---this may be more involved.

\p [digits]

\p 1

\p 18

\p 0

\p

/no argument given, print the current precision

tell kevin what needs writeups

Which pieces of the code need more explanation? Which pieces of the language are unclear to those working on it?

Which parts of the code are both wide-reaching and particularly opaque? What is confusing? Do dictionaries need a special writeup? The K object? The type 7 K object?

port to cygwin

Update C source to compile on cygwin. Update configure && make process

Feature: monadic ! enumerate for non-integer arguments

A. If the argument is a 1. dictionary 2. symbol corresponding to an entry on the k tree (dot-absolute or relative to current working dictionary), return a symbol vector corresponding to the keys. Pick nil or value error for invalid symbol arg.

B. If the argument is a char or char vec (+/- 3) then do an ls on the system directory and return it as a list of char vectors

  _d
`.k
  a:10
  b:20
  .k
.((`a;10;)
  (`b;20;))
  !`".k"
`a `b
  .k.c.d:30
  !`c
,`d

  z[`a `b]:1
  z
.((`a;1;)
  (`b;1;))
  !z
`a `b

  !"/usr/kona"    
("file1",
 "file2")

Feature: reusably compiled functions

{1+x} brace style functions are re-interpreted every time they are executed. It would be better if they were compiled. This will be tricky. Bytecode would be ideal, but even using internal the K execution format, there will still be the question of handling the LOCAL and other datastructure values in a sensible way.

\t {1+x}'!100000 /too slow

320.0 /ms

/Ackermann

ack:{:[0=x;y+1;0=y;_f[x-1;1];_f[x-1;_f[x;y-1]]]}

\t ack[3;6] /too slow

5420.0

Project Goal I

The first major project goal is to get Kona included in a package management system. Let's choose a specific package manager to target as a result of discussion. I should be able to type

sudo apt-get install k

or the equivalent on some system and have K available for use.

I am not sure how long this will take. I can think of at least four things we'll need to do on the way. Please add others.

  1. Identify necessary changes
  2. Pick a manager to target
  3. Change license (ISC?)
  4. Incorporate rlwrap functionality
  5. Build on 32-bit

Implement the \w workspace command

\w should return an integer vector consisting of: memory bytes in use, memory bytes allocated, and number of bytes mmapped

this should work cross-platform

some work on this exists in c.c

Feature: early return for functions

Right now, the return value of a function is the last expression executed. So for instance
{2;3;4}0 returns 4.

There is supposed to be a way to return early from functions using colon. So

{if[1=x; :10]; 20}1 would return 10.

Implementing this feature will require deep knowledge of the codebase.

Functions: Stop and Trace

Backslash \ has a special meaning inside functions when used at the beginning of expressions. When trace is on, the value is printed, and when stop is on, execution additionally halts after the value is printed. This is like debugging inside of functions. You can also turn this debugging off.

The \b command controls whether \ does a trace, stop, or nothing. The \b command with no arguments reports the value.

{\x; ... }   / potentially print the value of x, potentially carry on with execution

console should print some escapes specially

Edit the showAtDepth function so that the following escape characters are printed using the form "\c" , where c is the corresponding identifying character.

\"
\\
\b
\n
\r
\t

note: b is \010 and not \007

  "\""
"""    /wrong, expected "\""
  "\n"
"\012" /wrong, expected "\n"

bsd crashes

crashing on openbsd, working on osx/linux. apparently crashing in showAtDepth()

$'+
$+
4'  
**
@#$>
&&

Feature: sorting for functions

Update KC() ("K compare") to provide a sensible comparison function (results in {-1,0,1}) for 7-types. This will let us sort functions. This will be trickier than for dictionaries since there are several differents types of functions and projections.

< ({x+1};{x+y};{x*2})
/????

Feature: d[.] returns list of dictionary entry attributes

For dictionary d the expression d[.] should return a list of dictionary entry attributes (the third values in the list for each entry). Probably the way to go about this is to check for dyadic dot in the same special way @ amend or . amend check for dyadic colon for the purposes of assignment (eg in @[0 1 2 3 4;2;:;5] )

There is a ticket open for !d - enumerate dictionary keys
d[] - dictionary values already works

\t => divide by zero

d=(clock()-d)/(CLOCKS_PER_SEC/1000);
should be
d=(clock()-d)/((F)CLOCKS_PER_SEC/1000);
as x/ (CLOCKS_PER_SEC/1000) can become x/0 otherwise.

Harbison & Steele 5 recommends this, too (pg. 443).

Pull request coming in a minute.

tutorial

Create tutorials for K. On the wiki or linked from the wiki.

I like the thinking behind Erlang's 'Getting Started' format, which has 'Getting Started Quickly', 'Getting Started Slowly', and 'Getting Started Very Slowly'. Some programmers are quick studies and will want to get to the crux immediately. Others will want to take their time and have the rationale behind things explained, say for avoiding the do-loop. We can offer several tutorials and let people take their pick.

Feature: working 32-bit compilation

Kona doesn't compile properly/work for 32-bit systems. There are a few incompatibilities. Remove compile errors. Make I/O verbs behave sensibly. Create safe variations of cl2() and rp2().

wiki: project euler solutions

On the wiki, create a list of solutions to the first 10 (20, 30, ...) project euler problems. The list should be maintained using code golf rules, with shorter solutions replacing existing longer ones. Each solution should be credited to the author

implement _ceiling

I pushed a minor change that added the C math function ceil as _ceil. This is like _floor in that it is intolerant. _floor has a tolerant version, the monadic form of underscore. The _ceil verb should have a tolerant version as well, call it '_ceiling'. This verb should work on lists of arbitrary depth. You can implement this the long way in C, following the example of monadic underscore, or you can implement it in K, following the example of other similarly implemented verbs (eg '_dot' or +/* ), as "-_-:" (negate floor negate).

Add tests that demonstrate the tolerance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.