q vs python: Gotchas

(Series) A side-by-side comparison of q/kdb+ and python for qbies (q newbies).

Cover image

This post will continually get updated as I earn more burn scars...

Order of precedence*

In q, an expression is evaluated right-to-left, (almost) always.

See image above for some examples.

Combined with in-line variable assignment, one can do things like:

q) n where 0 = (n:til 20) mod 3
0 3 6 9 12 15 18

Accidentally creating globals*

Watch out for typos that will create a global variable.

q) f:{[] symList:`a`b`c; synList,:`d; };  // typo!

q) symList  // is undefined
'symList

q) synList  // is defined!
,`d
>>> def f():
...     sym_list = ["a", "b", "c"]
...     syn_list.append("d")  # typo!
...
>>> f()
NameError: name 'syn_list' is not defined