In q, there are several ways to apply a function and index a variable. Underlying them all is the ur-function Apply/Index
.
pronounced dot. Application of the rank-n function f
to a list of arguments v
of count n is expressed:
f . v
The only place you can fall from
is where it’s at; and when you’re down,
you’re not there – that’s why.
— Alastair Howard Robertson
Application of the unary function g
to w
is expressed:
g . enlist w
sugar for which is
g@w
Even more simply:
g w
Brackets are more sugar:
f[first v;…;last v]
g[w]
Maximize readability by using the simplest syntax available.
All functions can be applied with bracket notation. Infix and prefix syntax is usually clearer and preferable.
+[2;2] 2+2
til[5] til 5
Not always, particularly when composing the left argument of an infix.
Short expressions within brackets or parentheses are clearer than long expressions. Bracket notation can avoid parenthesizing a longer expression.
+/[foo goo v] / less clear
(+/) foo goo v / more clear
bar[(+//)m; goo v] / less clear
((+//)m) bar goo v / clearer?
+//[m] bar goo v / clear
Minimize the distance between opening and closing brackets and parentheses.