Skip to content

eval, reval

Evaluate parse trees


Evaluate a parse tree

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


Restricted evaluation of a parse tree

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;enlist x)} / define in process listening on port 5000
q)h:hopen 5000 / from another process on same host
'noupdate: `. `a

Behaves as if command-line options -u 1 and -b were active; also blocks all system calls which change state. That is, all writes to file system are blocked; allows read access to files in working directory and below only; and prevents amendment of globals. (Since V4.0 2020.03.17.)

Internal function -6!
Table counts in a partitioned database