Skip to content

Commit 4a6ee7f

Browse files
Shati Pateljames
authored andcommitted
QL HB: Add predicate call example [SD-3864]
(cherry picked from commit cfa51a0)
1 parent 52583d0 commit 4a6ee7f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

docs/language/ql-handbook/queries.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ For example::
8383
result = x * y
8484
}
8585

86-
This predicates returns the following results:
86+
This predicate returns the following results:
8787

8888
+---+---+--------+
8989
| x | y | result |
@@ -96,8 +96,14 @@ This predicates returns the following results:
9696
+---+---+--------+
9797

9898
A benefit of writing a query predicate instead of a select clause is that you can call the
99-
predicate in other parts of the code too. In contrast, the select clause is like an anonymous
100-
predicate, so you can't call it later.
99+
predicate in other parts of the code too. For example, you can call ``getProduct`` inside
100+
the body of a :ref:`class <classes>`::
101+
102+
class MultipleOfThree extends int {
103+
MultipleOfThree() { this = getProduct(_, _) }
104+
}
105+
106+
In contrast, the select clause is like an anonymous predicate, so you can't call it later.
101107

102108
It can also be helpful to add a ``query`` annotation to a predicate while you debug code. That
103109
way you can explicitly see the set of tuples that the predicate evaluates to.

0 commit comments

Comments
 (0)