Skip to content

eval, reval

Evaluate a parse tree


Syntax: eval x, eval[x]

Where x is a parse tree, returns the result of evaluating it.

The eval function is the complement of parse and can be used to evaluate the parse trees it returns. (Also parse trees constructed explicitly.)

q)parse "2+3"
q)eval parse "2+3"
q)eval (+;2;3)      / constructed explicitly


Syntax: reval x, reval[x]

The reval function is similar to eval, and behaves as if the command-line option -b were active during evaluation.

An example usage is inside the message handler, useful for access control, here blocking sync messages from updating:

q){reval(value;x)} / define in process listening on port 5000
q)h:hopen 5000 / from another process on same host
'noupdate: `. `a

Partitioned databases

For partitioned databases, q caches the count for a table, and this count cannot be updated from within a reval expression or from a slave thread. Thus to avoid 'noupdate on queries on partitioned tables you should put count table in your startup script.

Basics: Internal function -6!