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 . vThe 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 wsugar for which is
g@wEven more simply:
g wBrackets 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 5Not 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 / clearMinimize the distance between opening and closing brackets and parentheses.