Skip to content


This guide explains why a shadowed variable error may occur and describes how to fix it.

In Rel, all variables have to be explicitly introduced to clarify their scope. Moreover, they are introduced by bindings. For instance, a local scalar variable x shadows relation definitions, schema, and natives with name x.

Consider the following example that returns a shadowed variable error:

def names = {"Patrick"; "Joe"}
def dbl_names(n, n) = names(n)
Error example from the RAI Console

The query above defines the relation dbl_names with the purpose of doubling the elements of the tuples in the relation names. However, the system interprets this as two different variables with the same name. Hence, this query triggers a shadowed variable error.

To fix this, you need to use a different name for every new variable that gets introduced in the binding. In the updated example below, the second variable is now m. The condition n=m ensures that both variables have the same value.

// read query
def names = {"Patrick"; "Joe"}
def dbl_names(n, m) = {names(n) and n=m}
def output = dbl_names
Was this doc helpful?