Let's define deparse
1 as inverse operation to q's native parse
, so that the following holds:
q)aStringQExpression~deparse parse aStringQExpression
1b
Question
What's the definition of deparse
function so that the above indeed works?
For example, in the below update expression, we know that "a*0^b+c-d"
expression corresponds to (*;`a;(^;0;(+;`b;(-;`c;`d))))
parse tree:
q)-3!parse "update col:a*0^b+c-d from t"
"(!;`t;();0b;(,`col)!,(*;`a;(^;0;(+;`b;(-;`c;`d)))))"
So the envisaged deparse
function should return:
q)deparse "(*;`a;(^;0;(+;`b;(-;`c;`d))))"
"a*0^b+c-d"
q)deparse "(!;`t;();0b;(,`col)!,(*;`a;(^;0;(+;`b;(-;`c;`d)))))"
"update col:a*0^b+c-d from t"
Motivation/Background/Use case: Inline expressions are arguably faster to grok by human eye (left-to-right) than deeply nested parse trees. Although in the background my code is editing the parse tree programatically, it is useful for debugging or presentation to conveniently convert that resulting parse tree into inline expression string.
1 Similar functionality described here: http://adv-r.had.co.nz/Expressions.html#parsing-and-deparsing