Search code examples
kdbk

How to build a parse-tree of projections?


I want to save somehow a parse-tree into a text format file, than bring it back to q.

But a parse-tree could possibly contains projections, say +[;1]2. How should I process these file trees and correctly save/load it? I've got errors trying to work directly with :: in the following example:

parse"+[;1]2"
(parse"+[;1]2")[0] / (+; ::; 1)
null(parse"+[;1]2")[0;1] / 0b, something strange
null(::) / 1b
eval((+;::;1);2) / 3

One way to resolve this, I think, to replace all :: with empty string, and than apply eval/

(eval/)((+;;1);2) / ok

But there are other cases when :: are necessary, for example:

m:(1 2;3 4)
parse ".[m;(::;1)]1"
eval ((.;`m;(enlist;::;1));1) / 4
eval ((.;`m;(enlist;;1));1) / error: 'type

So how could I correctly save(/load) a parse tree in a text format for both these cases?

Am I want something strange? Is it possible to get one-to-one Abstract Syntax Tree program representation in q?


Solution

  • What you've accidentally stumbled across there is what Andrey Kozyrev calls "magic value", see here: https://github.com/quintanar401/DCoQ

    But yes, what you're trying to achieve is strange and certainly not common usage. What exactly do you hope to gain from doing this?