Skip to content


This guide explains why an undefined error may occur and describes how to fix it.

In Rel, a variable is undefined if there’s no lexically enclosing declaration. Undefined errors occur most commonly when referring to a relation that hasn’t yet been defined. Referring to relations within modules requires particular attention.

Consider the following example that returns an undefined error:

def zoes_friends = friends["Zoe"] 
Error example from the RAI Console

In the query above, the relation zoes_friends defines Zoe’s friends. However, the relation friends hasn’t been previously defined.

Here’s one way to write the example correctly:

// read query
def friends = {("Mike", "Anna"); ("Zoe", "Jenn")}
def zoes_friends = friends["Zoe"]
def output = zoes_friends

This returns Zoe’s friends list.

It’s also possible that you’ve already defined the relation friends but the compiler isn’t able to find it. For instance, suppose you define the relation within a module:

module friends_mod
    def friends = {("Mike", "Anna"); ("Zoe", "Jenn")}

If you then query zoes_friends as in the first example, the output still returns this error. You can think of Rel modules as nested relations. In the example above, the relation friends is nested inside friends_mod and available as friends_mod[:friends], equivalent to friends_mod:friends.

Therefore, a valid definition of zoes_friends could be:

def zoes_friends = friends_mod:friends["Zoe"]

Similarly, say while installing some logic as a model, you refer to relations that you haven’t defined yet, but that you plan to define later in a different model or query. This returns an undefined error:

Error example from the RAI Console

In this case, you can ignore the error as long as you provide the definition later. See Working With Models for more details.

Was this doc helpful?