Declarations bind names to values. Variables are declared inside the global section of the rule set, the rule prelude, functions, and user-defined actions.

The expression on the right is evaluated and its value is bound to the variable on the left. The right-hand side can be any valid expression

Function declarations are separated by semicolons.

The following example shows two variables, x and y, being declared:

x = 5;
y = event:attr("url").extract(#http://(\[^/?]+)#)

KRL is statically scoped. Each place where an identifier is bound in a program corresponds to a region of the program text within which the binding is visible. The region is determined by the particular programmatic context where the binding is made:

KRL variable declarations are not variable assignments. Neither can KRL expressions cause persistent side effects. For example, the second declaration in the following prelude does not change the value to which x is bound. Rather, it results in two bindings of x, one of which is hidden (shadowed) by the other:

x = 5;
x = x + 6;

Developers should avoid treating declarations as assignments because they will invariably be surprised by the resulting semantics in subtle ways.