Understanding behavior of recursive functions

I am trying to see if I can get a better understanding of this example
fun transitive_places($place: place) -> { place }:
match
{
locating (located: $place, location: $parent);
} or {
locating (located: $place, location: $middle);
let $parent in transitive_places($middle);
};
return { $parent };
fun transitive_places($place: place) -> { place }:
match
{
locating (located: $place, location: $parent);
} or {
locating (located: $place, location: $middle);
let $parent in transitive_places($middle);
};
return { $parent };
In the statement let $parent in transitive_places($middle);, is the variable $parent scoped only to its branch of the disjunction or the entire disjunction?
1 Reply
krishnan
krishnan21h ago
Entire disjunction. I've tried to explain the variable naming rules here: https://typedb.com/docs/core-concepts/typeql/query-variables-patterns#_disjunctions The tl;dr is variable names are scoped to the pipeline - in this case the whole body of the function. (Select, delete, and (I think) reduce stages free up variable names to be re-used in subsequent stages)

Did you find this page helpful?