K Programming Language

#programming-language

An excellent explanation of K syntax:

:

----- Original Message -----
From: Christian Tismer <tismer@...>
To: <concatenative@egroups.com>
Sent: Sunday, May 28, 2000 12:48 PM
Subject: Re: [stack] joy applications


>
>
> "Samuel A. Falvo II" wrote:
> >
> > On Sat, 27 May 2000, stevan apter wrote:
> > > Tree..d:".+(`child`parent
> > > +{x@<x}@+{[l;n;p;c]
> > > (c;p),' :[l&(~c)|()_draw l+1
> > > ,'/_f[l-1;n;c]'{x;:I+:1}'!2+()_draw n
> > > 2#,!0]}[Levels;Nodes;0;I::0])"
> >
> > Oh my God! I never thought it possible! I've actually seen a
>programming
> > language that's harder to read than Perl!! 8)
>
> Then try out APL. It can for sure compete with the above
> (WOL = Write Only Language) :-)

actually, k syntax is extremely simple.

we recognize three syntax categories: noun, verb, and adverb.

there are exactly 20 verbs:

~ ! @ # $ % ^ & * _ - + = | : < , > . ?

each verb can be monadic, in which case it is prefixed to its
noun:

^x

or dyadic, in which case it is written infix:

x^y

there is no precedence.

there are six adverbs:

' \ / ': /: \:

an adverb is suffixed to its verb or noun:

+/
-':
p\

verbs take nouns to make nouns; adverbs take verbs and nouns to
make verbs.

the parsing rules are given in two tables. one table gives the
binding strengths between categories:

n n 1
n v 3
n a 4
v n 2
v v 1
v a 4

the other gives the result of binding two categories:

n n -> n / application
n v -> v / curry
n a -> v / modify noun
v n -> n / monadic application
v v -> v / composition
v a -> v / modify verb

parsing is simple: scan from the right; when a drop in binding
strength occurs, bind the pair at that position and replace it
with the category of the result.

nouns are datatypes. in k, there are exactly 8:

int
float
byte
symbol
dictionary
null
lambda
list

the shape of k has been strongly influenced by thousands of man-
years spent writing applications for trading-floor environments.
such environments are characterized by the demand for high
productivity, large volumes of data, speed of execution, and zero
tolerance for errors. in such an environment, a "write only language"
would be quickly targetted for extinction.

>
> ciao - chris
>
> --
> Christian Tismer :^)

source. Via @silentbicycle


An introduction to K by Arthur Whitney. via

Q for Mortals book online from kx.com

https://kparc.io+/kei | K reference card

Related: