Skip to content

Commit 80de755

Browse files
authored
Merge pull request github#3043 from shati-patel/2173-tutorials
CodeQL docs migration prep: Update QL tutorials
2 parents 554981e + 92d82a9 commit 80de755

14 files changed

+370
-372
lines changed

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

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
Catch the fire starter: Classes and predicates
2-
==============================================
1+
Catch the fire starter
2+
======================
3+
4+
Learn about QL predicates and classes to solve your second mystery as a QL detective.
35

46
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!
57

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

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

106-
Continue to the :doc:`next page <fire-2>` to gather more clues and find out which of your suspects started the fire...
108+
You can now continue to gather more clues and find out which of your suspects started the fire...
109+
110+
Identify the bald bandits
111+
-------------------------
112+
113+
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.
114+
115+
This is a very helpful clue. Remember that you wrote a QL query to select all bald people:
116+
117+
.. code-block:: ql
118+
119+
from Person p
120+
where not exists (string c | p.getHairColor() = c)
121+
select p
122+
123+
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``.
124+
125+
.. code-block:: ql
126+
127+
predicate isBald(Person p) {
128+
not exists (string c | p.getHairColor() = c)
129+
}
130+
131+
The property ``isBald(p)`` holds whenever ``p`` is bald, so you can replace the previous query with:
132+
133+
.. code-block:: ql
134+
135+
from Person p
136+
where isBald(p)
137+
select p
138+
139+
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.
140+
141+
You can now write a query to select the bald southerners who are allowed into the north.
142+
143+
➤ `See the answer in the query console <https://lgtm.com/query/2572701606358725253/>`__
144+
145+
You have found the two fire starters! They are arrested and the villagers are once again impressed with your work.
146+
147+
What next?
148+
----------
149+
150+
- Find out who will be the new ruler of the village in the :doc:`next tutorial <crown-the-rightful-heir>`.
151+
- Learn more about predicates and classes in the `QL language handbook <https://help.semmle.com/QL/ql-handbook/index.html>`__.
152+
- Explore the libraries that help you get data about code in :doc:`Learning CodeQL <../../index>`.

docs/language/learn-ql/ql-etudes/river-crossing.rst renamed to docs/language/learn-ql/beginner/cross-the-river.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
River crossing puzzle
2-
#####################
1+
Cross the river
2+
===============
33

4-
The aim of this tutorial is to write a query that finds a solution to the following classical logic puzzle:
4+
Use common QL features to write a query that finds a solution to the "River crossing" logic puzzle.
5+
6+
Introduction
7+
------------
58

69
.. pull-quote::
710

docs/language/learn-ql/beginner/heir.rst renamed to docs/language/learn-ql/beginner/crown-the-rightful-heir.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Crown the rightful heir
22
=======================
33

4+
This is a QL detective puzzle that shows you how to use recursion in QL to write more complex queries.
5+
6+
King Basil's heir
7+
-----------------
8+
49
Phew! No more crimes in the village—you can finally leave the village and go home.
510

611
But then... During your last night in the village, the old king—the great King Basil—dies in his sleep and there is chaos everywhere!
@@ -9,9 +14,6 @@ The king never married and he had no children, so nobody knows who should inheri
914

1015
Eventually you decide to stay in the village to resolve the argument and find the true heir to the throne.
1116

12-
King Basil's heir
13-
-----------------
14-
1517
You want to find out if anyone in the village is actually related to the king. This seems like a difficult task at first, but you start work confidently. You know the villagers quite well by now, and you have a list of all the parents in the village and their children.
1618

1719
To find out more about the king and his family, you get access to the castle and find some old family trees. You also include these relations in your database to see if anyone in the king's family is still alive.
@@ -136,7 +138,7 @@ To decide who should inherit the king's fortune, the villagers carefully read th
136138

137139
*"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."*
138140

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-thief-1>` and :doc:`Catch the fire starter <fire-1>` tutorials).
141+
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).
140142

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

@@ -160,5 +162,5 @@ What next?
160162
----------
161163

162164
- Learn more about recursion in the `QL language handbook <https://help.semmle.com/QL/ql-handbook/index.html>`__.
163-
- Put your QL skills to the test and solve the :doc:`River crossing puzzle <../ql-etudes/river-crossing>`.
165+
- Put your QL skills to the test and solve the :doc:`River crossing puzzle <cross-the-river>`.
164166
- Start using QL to analyze projects. See :doc:`Learning CodeQL <../../index>` for a summary of the available languages and resources.

0 commit comments

Comments
 (0)