Skip to content

Commit f48b8fe

Browse files
authored
Merge pull request #2575 from shati-patel/qlhb/bindingset
QL HB: Add bindingset example
2 parents 7e987c5 + f38ae3c commit f48b8fe

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

docs/language/ql-handbook/predicates.rst

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,23 @@ Multiple binding sets specified this way are independent of each other. The abov
271271
- If ``y`` is bound, then ``x`` and ``y`` are bound.
272272

273273
That is, ``bindingset[x] bindingset[y]``, which states that at least one of ``x`` or ``y`` must
274-
be bound, is different from ``bindingset[x,y]``, which states that both ``x`` and ``y`` must be
274+
be bound, is different from ``bindingset[x, y]``, which states that both ``x`` and ``y`` must be
275275
bound.
276276

277+
The latter can be useful when you want to declare a :ref:`predicate with result <predicates-with-result>` that takes multiple input arguments.
278+
For example, the following predicate takes a string ``str`` and truncates it to a maximum length of ``len`` characters::
279+
280+
bindingset[str, len]
281+
string truncate(string str, int len) {
282+
if str.length() > len
283+
then result = str.prefix(len)
284+
else result = str
285+
}
286+
287+
You can then use this in a :ref:`select clause <select-clauses>`, for example::
288+
289+
select truncate("hello world", 5)
290+
277291
.. _database-predicates:
278292

279293
Database predicates
@@ -283,7 +297,7 @@ Each database that you query contains tables expressing relations between values
283297
("database predicates") are treated in the same way as other predicates in QL.
284298

285299
For example, if a database contains a table for persons, you can write
286-
``persons(x, firstName, _, age)`` to constrain ``x``, ``firstName`` and ``age`` to be the
300+
``persons(x, firstName, _, age)`` to constrain ``x``, ``firstName``, and ``age`` to be the
287301
first, second, and fourth columns of rows in that table.
288302

289303
The only difference is that you can't define database predicates in QL. They are defined by the

0 commit comments

Comments
 (0)