Skip to content

Commit 4696ee5

Browse files
committed
c_tutorial.rst: Incorporate review comments.
1 parent 7649255 commit 4696ee5

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

doc/c_tutorial/c_tutorial.rst

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Integrating C with DDlog
33
************************
44

5+
**Thank you, @smadaminov, for kindly contributing this tutorial!**
6+
57
.. contents::
68

79
Prerequisites
@@ -15,28 +17,27 @@ There is also an expectation that you are familiar with DDlog syntax and command
1517
Introduction
1618
============
1719

18-
In this set of tutorials we are going to explore various features of DDlog programming language and learn how to integrate DDlog program into C program.
20+
In this set of tutorials we are going to explore various features of DDlog programming language and learn how to integrate a DDlog program into a C program.
1921
To do that we are going to build a simple yet functional application as it is more fun to build real programs.
2022
We will start by writing a simple program with a limited functionality to get familiar with the basics of DDlog.
2123
Afterwards, over the course of this set of tutorials, we will gradually improve our application by applying more advanced techniques offered by DDlog.
2224

2325
Tutorial #1 - Reachability Monitor
2426
==================================
2527

26-
In our first tutorial we are going to build a program that will calculate the reachability information in the network.
28+
In our first tutorial we are going to build a program that will calculate the reachability information in a network composed of nodes connected by links.
2729
User will update link status between nodes through CLI and our program will calculate the rest.
2830
The purpose of this program is to provide a simple interface to a network operator and return information regarding which node can reach which.
2931
Thus, the only concern of network operator is to update link status without having to worry about doing those calculations themself.
3032
We are going to test our program with the network consisting of four nodes: Menlo Park, Santa Barbara, Los Angeles, and Salt Lake City.
3133
However, nothing prevents us from using the network comprised of hundreds of nodes.
3234

3335
Let's start with defining our program in the DDlog language.
34-
In our program we need to supply source node, destination node, and a link status between them.
3536
Now we are ready to define our input relation :code:`Links`.
3637
Let's create a file called :code:`t1_reachability_monitor.dl` and add there a following line representing input relation for our reachability monitor:
3738

3839
.. code-block::
39-
40+
4041
input relation Links(src: string, dst: string, link_status: bool)
4142
4243
However, for the reachability monitor to be useful it also should provide some output and not just ingest the data.
@@ -58,7 +59,6 @@ First, we say that any two directly connected nodes such that the :code:`link_st
5859
Furthermore, any two nodes are considered connected if there is path from the source node to the destination node such that all directly connected nodes along the path also have the :code:`link_status` between them to be :code:`true`.
5960
Take a minute here to realize how easy it is to write such rule in DDlog.
6061
While these rules may not require much effort in other programming languages, the distinct feature of DDlog is that the computing is done incrementally!
61-
Isn't is amazing?
6262

6363
With that done, let's compile and start our program.
6464
We will feed our DDlog code to the DDlog compiler and it will generate a new folder.
@@ -88,7 +88,7 @@ To make our life more interesting (and just slightly more complicated) the links
8888

8989
.. image:: ./images/topology.jpg
9090

91-
Note that DDlog is a `transaction-based`_ programming language.
91+
Note that DDlog exposes a `transaction-based`_ API.
9292
Each transaction begins with a :code:`start` command and ends with a :code:`commit` command.
9393
Let's start DDlog shell again and insert records to recreate the network topology above:
9494

@@ -122,8 +122,8 @@ Let's start DDlog shell again and insert records to recreate the network topolog
122122
In the output we can see all cities with direct links between them are connected.
123123
Furthermore, as we specified in our DDlog code, if there is a path between two cities then they are also connected, e.g., Menlo Park is connected to Los Angeles.
124124
However, some nodes are connected to themselves.
125-
But why this happened?
126-
If we take a closer look at our rules we can notice that this phenomenon actually make sense.
125+
How did this happen?
126+
If we take a closer look at our rules we can notice that this phenomenon actually makes sense.
127127
For example, Santa Barbara is reachable from Santa Barbara through Los Angeles.
128128
While it is not necessarily horrible or wrong we may want to avoid it as it clutters the relation and the output.
129129
More notably, we definitely don't want the network traffic go to Santa Barbara from Santa Barbara through Los Angeles (in the real world this actually may happen but this is a completely different topic).
@@ -395,8 +395,7 @@ We need to provide this function with the table ID of a target relation and a re
395395
Once we have command ready we can apply it to our DDlog program using :code:`ddlog_apply_updates()` function.
396396
We need to supply program handle, array of commands to be applied, and the length of this array.
397397
In our case, we only have a single command to apply.
398-
However, it is possible to pass multiple commands to a single call to the :code:`ddlog_apply_update()` function.
399-
It helps avoiding cluttering code if you want to apply multiple commands.
398+
However, it is possible (and is more efficient) to pass multiple commands to a single call to the :code:`ddlog_apply_update()` function.
400399
Note, that in the case of multiple commands if some of them fail then some subset of commands may still be applied.
401400
Please refer to the API description in the :code:`ddlog.h` header file for more details.
402401

0 commit comments

Comments
 (0)