|
@@ -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
|
|
|
+----------------
|