Skip to content

Commit 992c61a

Browse files
author
Shati Patel
committed
Combine and rename second detective tutorial
1 parent d0d34d6 commit 992c61a

5 files changed

Lines changed: 50 additions & 49 deletions

File tree

docs/language/learn-ql/beginner/fire-1.rst renamed to docs/language/learn-ql/beginner/catch-the-fire-starter.rst

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Catch the fire starter: Classes and predicates
2-
==============================================
1+
Catch the fire starter
2+
======================
33

44
Just as you've successfully found the thief and returned the golden crown to the castle, another terrible crime is committed. Early in the morning, a few people start a fire in a field in the north of the village and destroy all the crops!
55

@@ -103,4 +103,48 @@ You know that the fire starters live in the south *and* that they must have been
103103

104104
➤ `See the answer in the query console <https://lgtm.com/query/2551838470440192723/>`__
105105

106-
Continue to the :doc:`next page <fire-2>` to gather more clues and find out which of your suspects started the fire...
106+
You can now continue to gather more clues and find out which of your suspects started the fire...
107+
108+
Identify the bald bandits
109+
-------------------------
110+
111+
You ask the northerners if they have any more information about the fire starters. Luckily, you have a witness! The farmer living next to the field saw two people run away just after the fire started. He only saw the tops of their heads, and noticed that they were both bald.
112+
113+
This is a very helpful clue. Remember that you wrote a QL query to select all bald people:
114+
115+
.. code-block:: ql
116+
117+
from Person p
118+
where not exists (string c | p.getHairColor() = c)
119+
select p
120+
121+
To avoid having to type ``not exists (string c | p.getHairColor() = c)`` every time you want to select a bald person, you can instead define another new predicate ``isBald``.
122+
123+
.. code-block:: ql
124+
125+
predicate isBald(Person p) {
126+
not exists (string c | p.getHairColor() = c)
127+
}
128+
129+
The property ``isBald(p)`` holds whenever ``p`` is bald, so you can replace the previous query with:
130+
131+
.. code-block:: ql
132+
133+
from Person p
134+
where isBald(p)
135+
select p
136+
137+
The predicate ``isBald`` is defined to take a ``Person``, so it can also take a ``Southerner``, as ``Southerner`` is a subtype of ``Person``. It can't take an ``int`` for example—that would cause an error.
138+
139+
You can now write a query to select the bald southerners who are allowed into the north.
140+
141+
➤ `See the answer in the query console <https://lgtm.com/query/2572701606358725253/>`__
142+
143+
You have found the two fire starters! They are arrested and the villagers are once again impressed with your work.
144+
145+
What next?
146+
----------
147+
148+
- Find out who will be the new ruler of the village in the :doc:`next tutorial <heir>`.
149+
- Learn more about predicates and classes in the `QL language handbook <https://help.semmle.com/QL/ql-handbook/index.html>`__.
150+
- Explore the libraries that help you get data about code in :doc:`Learning CodeQL <../../index>`.

docs/language/learn-ql/beginner/find-the-thief.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,6 @@ Have you found the thief?
292292
What next?
293293
----------
294294

295-
- Help the villagers track down another criminal in the :doc:`next tutorial <fire-1>`.
295+
- Help the villagers track down another criminal in the :doc:`next tutorial <catch-the-fire-starter>`.
296296
- Find out more about the concepts you discovered in this tutorial in the `QL language handbook <https://help.semmle.com/QL/ql-handbook/index.html>`__.
297297
- Explore the libraries that help you get data about code in :doc:`Learning CodeQL <../../index>`.

docs/language/learn-ql/beginner/fire-2.rst

Lines changed: 0 additions & 43 deletions
This file was deleted.

docs/language/learn-ql/beginner/heir.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ To decide who should inherit the king's fortune, the villagers carefully read th
136136

137137
*"The heir to the throne is the closest living relative of the king. Any person with a criminal record will not be considered. If there are multiple candidates, the oldest person is the heir."*
138138

139-
As your final challenge, define a predicate ``hasCriminalRecord`` so that ``hasCriminalRecord(p)`` holds if ``p`` is any of the criminals you unmasked earlier (in the :doc:`Find the thief <find-the-thief>` and :doc:`Catch the fire starter <fire-1>` tutorials).
139+
As your final challenge, define a predicate ``hasCriminalRecord`` so that ``hasCriminalRecord(p)`` holds if ``p`` is any of the criminals you unmasked earlier (in the :doc:`Find the thief <find-the-thief>` and :doc:`Catch the fire starter <catch-the-fire-starter>` tutorials).
140140

141141
➤ `See the answer in the query console <https://lgtm.com/query/1820692755164273290/>`__
142142

docs/language/learn-ql/beginner/ql-tutorials.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ some simple examples.
1717
Currently the following detective tutorials are available:
1818

1919
- :doc:`Find the thief <find-the-thief>`—a three part mystery that introduces logical connectives, quantifiers, and aggregates
20-
- :doc:`Catch the fire starter <fire-1>`—an intriguing search that introduces predicates and classes
20+
- :doc:`Catch the fire starter <catch-the-fire-starter>`—an intriguing search that introduces predicates and classes
2121
- :doc:`Crown the rightful heir <heir>`—a detective puzzle that introduces recursion
2222

2323
Further resources

0 commit comments

Comments
 (0)