Skip to content

Overloaded operators

Many non-alphabetic keyboard characters are overloaded. Operator overloads are resolved by rank, and sometimes by the type of argument/s.

@ at

rank syntax semantics
2 l@i, @[l;i] Index At
2 f@y, @[f;y] Apply At
3 @[f;y;e] Trap At
3 @[d;i;u] Amend At
4 a[d;i;m;my] Amend At
4 a[d;i;:;y] Replace At

\ backslash

rank syntax semantics
n/a \ ends multiline comment
n/a \ abort
1 (f\), f\[d] Converge
2 n f\d, f\[n;d] Repeat
2 t f\d, f\[t;d] While
2 x g\y, g\[x;y;z;…] map-reduce
d: data              n: non-negative integer
f: unary map         t: test map
g: map rank>1        x: atom or vector
                     y, z…: conformable atoms or lists

! bang

rank syntax semantics
2 x!y Dict: make a dictionary
2 i!ts Enkey: make a simple table keyed
2 0!tk Unkey: make a keyed table simple
2 noasv!iv Enumeration from index
2 sv!h Flip Splayed or Partitioned
2 0N!y display y and return it
2 -i!y internal function
4 ![t;c;b;a] Update, Delete
a: select specifications
b: group-by specifications
c: where-specifications
h: handle to a splayed or partitioned table
i: integer >0
i0: integer ≥0
noasv: symbol atom, the name of a symbol vector
sv: symbol vector
t: table
tk: keyed table
ts: simple table
x,y: same-length lists

- dash

Syntax: immediately left of a number, indicates its negative.



rank example semantics
2 2-3 Subtract

. dot

rank syntax semantics
2 l . i, .[l;i] Index
2 g . gx, .[g;gx] Apply
3 .[g;gx;e] Trap
3 .[d;i;u] Amend
4 .[d;i;m;my] Amend
4 .[d;i;:;y] Replace

$ dollar

rank example semantics
3 $[x>10;y;z] Cond: conditional evaluation
2 "h"$y, `short$y, 11$y Cast: cast datatype
2 "H"$y, -11$y Tok: interpret string as data
2 x$y Enumerate: enumerate y from x
2 10$"abc" Pad: pad string
2 (1 2 3f;4 5 6f)$(7 8f;9 10f;11 12f) dot product, matrix multiply, mmu

# hash

rank example semantics
2 2 3#til 6 Take
2 s#1 2 3 Set Attribute

? query

rank example semantics
2 "abcdef"?"cab" Find y in x
2 10?1000, 5?01b Roll
2 -10?1000, -1?`yes`no Deal
2 0N?1000, 0N?`yes`no Permute
2 x?v extend an enumeration: Enum Extend
3 ?[11011b;"black";"frame"] Vector Conditional
4 ?[t;b;c;a] Select, Exec
4 ?[t;i;x] Simple exec

' quote

rank syntax semantics
1 (f')x, f'[x], x ff'y, ff'[x;y;…] Each: iterate ff itemwise
1 'msg Signal an error
1 iv'[x;y;…] Case: successive items from lists
2 '[ff;f] Compose ff with f
f:  unary map         msg: symbol or string
ff: map of rank ≥1    x, y: data
iv: int vector

': quote-colon

rank example semantics
1 f': Each Parallel with unary f
1 g': Each Prior with binary g

/ slash

rank syntax semantics
n/a /a comment comment: ignore rest of line
1 (f/)y, f/[y] Converge
1 n f/ y, f/[n;y] Repeat
1 t f/ y, f/[t;y] While
1 (ff/)y, ff/[y] map-reduce: reduce a list or lists
f: unary map       t: test map     
ff: map rank ≥1    y: list
n: int atom ≥0

Syntax: a space followed by / begins a trailing comment. Everything to the right of / is ignored.

q)2+2 / we know this one

A / at the beginning of a line marks a comment line. The entire line is ignored.

q)/nothing in this line is evaluated

In a script, a line with a solitary / marks the beginning of a multiline comment. A multiline comment is terminated by a \ or the end of the script.

A script to add two numbers.
Version 2018.1.19
That's all folks.

_ underscore

rank example semantics
2 3_ til 10 Cut, Drop

Names can contain underscores

Best practice is to use a space to separate names and the Cut and Drop operators.

Unary forms

Many of the operators tabulated above have unary forms in k.

Exposed infrastructure