Klong Quick Reference

        ================================================================
        |              KLONG  **  A SIMPLE ARRAY LANGUAGE              |
        ================================================================

                                Quick Reference
                                By Nils M Holm
                             n m h @ t 3 x . o r g

        ----------------------------------------------------------------
        LEXEMES
        ----------------------------------------------------------------

        [a-zA-Z\.][a-zA-Z0-9\.]*         Symbol
        [!$%&*+,-\./;<=>?@\\^_|~]        Operator
        -?[0-9]+                         Integer
        -?[0-9]+\.[0-9]+                 Real
        -?[0-9]+(\.[0-9]+)?e[+-]?[0-9]+  Real
        0b[01]+                          Binary Integer
        0o[0-7]+                         Octal Integer
        0x[0-9a-f]                       Hexa-Decimal Integer
        0c.                              Character
        ".*"                             String, "" includes "
        \\~ \\*                          two-character Operator
        :Operator                        two-character Operator
        :String                          Comment
        :Symbol                          quoted Symbol
        :Number                          Number
        :Character                       Character

        ----------------------------------------------------------------
        SYNTAX
        ----------------------------------------------------------------

        # Program
        p := e
           | e ';' p

        # Expression
        e := x
           | x d e

        # Factor
        x := C
           | V a
           | V :a        # using :() instead of ()
           | f
           | f :a        # using :() instead of ()
           | m e
           | '(' e ')'
           | c
           | L
           | D

        # Lexeme class
        C := I   # integer
           | H   # character
           | R   # real number
           | S   # string
           | V   # variable (symbol)
           | Y   # (quoted) symbol

        # Conditional
        c := ':[' (e ';' e ':|')* e ';' e ';' e ']'

        # Monad
        m := O A*
           | f A+
           | V A+

        # Dyad
        d := O A*
           | f A+

        # Function
        f := '{' p '}'

        # Argument list
        a := '(' ')'
           | '(' e ')'
           | '(' e ';' e ')'
           | '(' e ':' e ';' e ')'

        # List
        L := '[' (C|L)* ']'

        # Dictionary
        D := ':{' t* '}'

        # Tuple
        t := '[' (C|L) (C|L) ']'

        ----------------------------------------------------------------
        VALUES
        ----------------------------------------------------------------

        Self-quoting:
        Integer, Real, Character, String, List, Dictionary, Symbols in
        Lists, Functions.

        Variables evaluate to their values.

        ----------------------------------------------------------------
        VERBS
        ----------------------------------------------------------------

        - monadic operators; +x
        - dyadic operators; x+y
        - nilads; f();      {1}:()
        - monads; f(x);     {x}:(1)
        - dyads;  f(x;y);   {x+y}:(1;2)
        - triads; f(x;y;z); {x+y+z}:(1;2;3)

        Function variables: "x", "y", "z". These are read-only.

        {1}      nilad
        {x}      monad
        {x+y}    dyad
        {x+y*z}  triad
        {z}      triad (ignoring x and y)

        Local Variables (initially undefined, dynamically scoped):

        {[variables];program}

        ----------------------------------------------------------------
        ATOMIC OPERATORS
        ----------------------------------------------------------------

        Operators that expect atomic (non-List) arguments traverse
        Lists automatically:

        a-[b c d]        =  (a-b),(a-c),(a-d)
        [b c d]-a        =  (b-a),(c-a),(d-a)
        [a b c]-[d e f]  =  (a-d),(b-e),(c-f)
        -[a b c]         =  (-a),(-b),(-c)
        [5 [6] 7]-4      =  [1 [2] 3]

        ----------------------------------------------------------------
        CONDITIONALS
        ----------------------------------------------------------------

        :[a;b;c]            =  if a then b else c
        :[a;b:|c;d;e]       =  :[a;b;:[c;d;e]]
        :[a;b:|c;d:|e;f;g]  =  :[a;b;:[c;d;:[e;f;g]]
        ...

        :[0;:yes;:no]   -->  :no
        :[[];:yes;:no]  -->  :no
        :["";:yes;:no]  -->  :no
        :[x;:yes;:no]   -->  :yes  :" for all other x"

        ----------------------------------------------------------------
        ADVERBS
        ----------------------------------------------------------------

        Each                 f'a   f(a1),...,f(aN)
        Each2              a f'b   f(a1;b1),...,f(aN;bN)
        Each-Left          a f:\b  f(a;b1),...,f(a;bN)
        Each-Right         a f:/b  f(b1;a),...,f(bN;a)
        Each-Pair            f:'b  f(a1;a2),...,f(aN-1;aN)
        Over                 f/a   f(...f(f(a1;a2);a3)...;aN)
        Over/Neutral       a f/b   f(...f(f(a;b1);b2)...;bN)
        Converge             f:~a  while ~a=f(a) do a::f(a); return a
        While              a f:~b  while a(b) do b::f(b); return b
        Iterate            a f:*b  do b::f(b) a times; return b
        Scan-Over            f\a   |                                   |
        Scan-Over/Neutral  a f\b   |  The Scan-* adverbs are like      |
        Scan-Converging      f\~a  |  their counterparts, but collect  |
        Scan-While         a f\~a  |  intermediate results and return  |
        Scan-Iterating     a f\*a  |  them in a list                   |

        ----------------------------------------------------------------
        OPERATORS
        ----------------------------------------------------------------

        a:=b  Amend            a$b   Format2          ~a    Not
        a:-b  Amend-in-Depth   >a    Grade-Down       a+b   Plus
        @a    Atom             <a    Grade-Up         a^b   Power
        :#a   Char             =a    Group            ?a    Range
        a:_b  Cut              a@b   Index/Apply      %a    Reciprocal
        a::b  Define           a:@b  Index-in-Depth   a:^b  Reshape
        a%b   Divide           a:%b  Integer-Divide   a!b   Remainder
        a_b   Drop             a,b   Join             |a    Reverse
        !a    Enumerate        a<b   Less             a:+b  Rotate
        a=b   Equal            ,a    List             ^a    Shape
        &a    Expand           a~b   Match            #a    Size
        a?b   Find             a|b   Max/Or           a:#b  Split
        *a    First            a&b   Min/And          a#b   Take
        _a    Floor            a-b   Minus            a*b   Times
        a:$b  Form             a>b   More             +a    Transpose
        $a    Format           -a    Negate           :_a   Undefined

        ----------------------------------------------------------------
        FUNCTIONS
        ----------------------------------------------------------------

        Names starting with "." are reserved for system use.

        .ac(a)  Append-Channel   .p(a)    Print
        .cc(a)  Close-Channel    .r()     Read
        .d(a)   Display          .rl()    Read-Line   
        .df(a)  Delete-File      .rn()    Random
        .E(a)   Evaluate         .rs(a)   Read-String
        .fc(a)  From-Channel     .sys(a)  System
        .ic(a)  Input-Channel    .tc(a)   To-Channel
        .l(a)   Load             .w(a)    Write
        .mi(a)  More-Input       .x(a)    Exit
        .oc(a)  Output-Channel

        ----------------------------------------------------------------
        VARIABLES
        ----------------------------------------------------------------

        .a  Arguments   command line arguments
        it  It          last result (interactive mode)
        .f  Function    current function
        .e  Epsilon     smallest precise real number

        ----------------------------------------------------------------
        BLOCK COMMENTS
        ----------------------------------------------------------------

        A block comment starts with

        .comment("delimiter")

        and ends with a line starting with the text given in .comment.
        The delimiter line is ignored. Block comments do not nest.

        ----------------------------------------------------------------
        MODULE STRUCTURE
        ----------------------------------------------------------------

        .l("external")
        .module(:name)
        :"... definitions ..."
        .module(0)

        ----------------------------------------------------------------
        INTERACTION
        ----------------------------------------------------------------

        ]!  Shell command
        ]i  Inventory
        ]l  Load
        ]q  Exit
        ]t  Transcript

        ================================================================

contact