How to extract and manipulate parse tree of a lambda/function?
E.g. given the function
pair:{` sv x,y}'
I'd like to arrive at the "inverse" version using a combinator called inverse
so that the following call returns (note the now swapped order of x
and y
):
q)inverse pair
{` sv y,x}'
The following works on embedded q functions and qsql, but not user-defined lambdas:
q)-3!parse "mavg"
"k){msum[x;0.0^y]%mcount[x;y]}"
q)-3!parse "select avg foo,sum bar by blah from myTable"
"(?;`myTable;();(,`blah)!,`blah;`foo`bar!((avg;`foo);(sum;`bar)))"
q) parse "pair"
`pair
q)-3!parse string pair
"(';{` sv x,y})"
Thanks