Skip to content

eval, reval

Evaluate parse trees

eval

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"
+
2
3
q)eval parse "2+3"
5
q)eval (+;2;3)      / constructed explicitly
5

reval

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 .z.pg, useful for access control, here blocking sync messages from updating:

q).z.pg:{reval(value;enlist x)} / define in process listening on port 5000
q)h:hopen 5000 / from another process on same host
q)h"a:4"
'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