How would I go about getting a list of available functions and their parameters in a given namespace?
3 Answers
http://code.kx.com/q/ref/syscmds/#f-functions
\f .
\f .namspace
For functions you will have to check parameters individually by just giving the name of function
.n.function
will give you not only the parameters but the whole function definition.

- 4,993
- 6
- 25
- 36

- 1,057
- 12
- 32
-
3I figured out that `get` could get me the parameters for a given function. http://code.kx.com/wiki/Reference/get – J.P. Armstrong Oct 05 '13 at 14:19
this can surely be improved upon, but thought I'd share as a quick way to get the ball rolling. This will retrieve every global user defined function in every workspace and create a dictionary of namespapaces to functions to parameters.
q)getparams:{k!{n[w]!@'[;1] value each f w:where 100h=type each f:get each ".",/:"." sv/:string x,/:n:y x}[;m] each key m:k!system each "f .",/:string k:key `}
q)f1:{x+y+z}
q).n1.f2:{x*x}
q).n1.a:2
q).n2.f3:{y+y}
q)show r:getparams[]
q | `aj`aj0`asc`asof`avgs`cols`cor`cov`cross`cut`desc`dev`each`ej`except`fby`..
Q | `Cf`IN`L`S`V`addmonths`bv`chk`cn`d0`dd`def`dpft`dpt`dsftg`dt`en`f`fc`ff`f..
h | `cd`code`data`eb`ec`ed`edsn`es`fram`ha`hb`hc`hn`hr`ht`hta`htac`htc`html`h..
n1| (,`f2)!,,`x
n2| (,`f3)!,`x`y
q)r[`n1;`f2]
,`x
[EDIT] the original function was wrong. It missed the global namespace (`) and didn't capture composition, or functions defined with an adverb. The below corrects this, but seems overly convoluted. I'll still leave it here though in case anyone wants to post a nicer solution (so that I too can learn from that)
getparams:{k!{n[w][w2]!@'[;1] v w2:where 0h=type each v:value/[{type[x] in y}[;t]; ] each f:f w:where in[ ;(t:"h"$100,105+til 7)] type each f:get each `$".",/:"." sv/:string x,/:n:y x}[;m] each key m:k!system each "f .",/:string k:`,key `}

- 1,891
- 13
- 29
-
I realize this an old thread but is there a way to reference just the first, blank name space i.e. I just want to build a dictionary of my custom functions vs. the native q functions? Thanks in advance, a very helpful thread! – Jason_L Nov 30 '20 at 19:54
I addition to Naveen's answer, you can call value functionName
which will give you a list of items, e.g. parameter names and the compiled byte code

- 4,411
- 4
- 25
- 48