Browse Source

Added example on how to use the prompt and server for Fibonacci numbers

Yentl Van Tendeloo 8 years ago
parent
commit
f0ee3099c6

BIN
doc/_build/doctrees/examples.doctree


BIN
doc/_build/html/_images/prompt_fibonacci.png


BIN
doc/_build/html/_images/prompt_fibonacci_more.png


+ 57 - 6
doc/_build/html/_sources/examples.txt

@@ -16,11 +16,62 @@ If you want to send integers or so, prepend the input with a backslash (\\), whi
 For example, input *5* will be received as the string "5".
 To send the integer 5, the input should be *\\5*.
 
-Simple Fibonacci Server
------------------------
+Fibonacci Server
+----------------
 
-Simple Petri Net Server
------------------------
+The first example is a simple Fibonacci server.
+The code is identical to the action language example from before, as this already included the *server* part (*i.e.*, the while loop).
+Now we will just connect to it using *prompt.py* and try out the code directly.
 
-Generic Modelling Server
-------------------------
+The code is repeated below::
+
+    include "primitives.alh"
+
+    Integer function fib(param : Integer):
+        if (param <= 2):
+            return 1!
+        else:
+            return fib(param - 1) + fib(param - 2)!
+
+    Void function main():
+        while(True):
+            output(fib(input()))
+
+To run this code, save it to a file (*e.g.*, fibonacci.alc) and execute the following command::
+
+    python scripts/run_local_modelverse.py 8001
+    
+Now, the Modelverse is running, but we still need to upload our code.
+To compile the file, together with the primitives.alc file, execute the following command::
+
+    python scripts/make_parallel.py http://localhost:8001 test fibonacci.alc bootstrap/primitives.alc
+
+When this finishes, the Modelverse now stores a copy of our code in its own format.
+The Modelverse will automatically create the user *test* and start executing the *main* function as this user.
+We can therefore simply connect to the Modelverse as the *test* user and start seeing the responses.
+To start the prompt, execute the following command::
+
+    python scripts/prompt.py
+    
+In this prompt tool, you first have to configure the location of the Modelverse and the username.
+The defaults should be fine, so just press <return> twice.
+After that, you are in direct connection with the Modelverse.
+Each message you type in, is made available in the *input()* function of the code.
+Remember that, to send integers, you have to prefix this with a backslash (\\).
+To get, for example, the 1st Fibonacci number, type in the command::
+
+    \1
+
+You will now see the following.
+
+.. image:: img/prompt_fibonacci.png
+
+Since we are in an unconditional loop, you can send as many requests as you want, as long as they are understandable by the *fib* function.
+
+.. image:: img/prompt_fibonacci_more.png
+
+Inputting a string directly, such as *1* instead of *\\1*, will make the Modelverse crash on the execution of this code.
+This is normal, though in the future the Modelverse will keep running for other users: only the current user's code will be interrupted.
+
+Modelling Server
+----------------

File diff suppressed because it is too large
+ 53 - 9
doc/_build/html/examples.html


+ 2 - 3
doc/_build/html/index.html

@@ -90,9 +90,8 @@
 </ul>
 </li>
 <li class="toctree-l1"><a class="reference internal" href="examples.html">Examples</a><ul>
-<li class="toctree-l2"><a class="reference internal" href="examples.html#simple-fibonacci-server">Simple Fibonacci Server</a></li>
-<li class="toctree-l2"><a class="reference internal" href="examples.html#simple-petri-net-server">Simple Petri Net Server</a></li>
-<li class="toctree-l2"><a class="reference internal" href="examples.html#generic-modelling-server">Generic Modelling Server</a></li>
+<li class="toctree-l2"><a class="reference internal" href="examples.html#fibonacci-server">Fibonacci Server</a></li>
+<li class="toctree-l2"><a class="reference internal" href="examples.html#modelling-server">Modelling Server</a></li>
 </ul>
 </li>
 <li class="toctree-l1"><a class="reference internal" href="advanced.html">Advanced examples</a><ul>

File diff suppressed because it is too large
+ 1 - 1
doc/_build/html/searchindex.js


+ 57 - 6
doc/examples.rst

@@ -16,11 +16,62 @@ If you want to send integers or so, prepend the input with a backslash (\\), whi
 For example, input *5* will be received as the string "5".
 To send the integer 5, the input should be *\\5*.
 
-Simple Fibonacci Server
------------------------
+Fibonacci Server
+----------------
 
-Simple Petri Net Server
------------------------
+The first example is a simple Fibonacci server.
+The code is identical to the action language example from before, as this already included the *server* part (*i.e.*, the while loop).
+Now we will just connect to it using *prompt.py* and try out the code directly.
 
-Generic Modelling Server
-------------------------
+The code is repeated below::
+
+    include "primitives.alh"
+
+    Integer function fib(param : Integer):
+        if (param <= 2):
+            return 1!
+        else:
+            return fib(param - 1) + fib(param - 2)!
+
+    Void function main():
+        while(True):
+            output(fib(input()))
+
+To run this code, save it to a file (*e.g.*, fibonacci.alc) and execute the following command::
+
+    python scripts/run_local_modelverse.py 8001
+    
+Now, the Modelverse is running, but we still need to upload our code.
+To compile the file, together with the primitives.alc file, execute the following command::
+
+    python scripts/make_parallel.py http://localhost:8001 test fibonacci.alc bootstrap/primitives.alc
+
+When this finishes, the Modelverse now stores a copy of our code in its own format.
+The Modelverse will automatically create the user *test* and start executing the *main* function as this user.
+We can therefore simply connect to the Modelverse as the *test* user and start seeing the responses.
+To start the prompt, execute the following command::
+
+    python scripts/prompt.py
+    
+In this prompt tool, you first have to configure the location of the Modelverse and the username.
+The defaults should be fine, so just press <return> twice.
+After that, you are in direct connection with the Modelverse.
+Each message you type in, is made available in the *input()* function of the code.
+Remember that, to send integers, you have to prefix this with a backslash (\\).
+To get, for example, the 1st Fibonacci number, type in the command::
+
+    \1
+
+You will now see the following.
+
+.. image:: img/prompt_fibonacci.png
+
+Since we are in an unconditional loop, you can send as many requests as you want, as long as they are understandable by the *fib* function.
+
+.. image:: img/prompt_fibonacci_more.png
+
+Inputting a string directly, such as *1* instead of *\\1*, will make the Modelverse crash on the execution of this code.
+This is normal, though in the future the Modelverse will keep running for other users: only the current user's code will be interrupted.
+
+Modelling Server
+----------------

BIN
doc/img/prompt_fibonacci.png


BIN
doc/img/prompt_fibonacci_more.png