123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- Examples
- ========
- To run this code, store it in a file (*e.g.*, test.alc), and execute the following commands::
- python scripts/run_local_modelverse.py 8001 &
- python scripts/make_parallel.py http://localhost:8001 test test.alc bootstrap/primitives.alc
- python scripts/prompt.py
- In the prompt, log on to http://localhost:8001 as user *test*.
- Now, all input you send, will be caught in the *input()* calls seen in the code.
- Results will also be printed.
- Note that all content will, by default, be typed as string.
- If you want to send integers or so, prepend the input with a backslash (\\), which allows you to directly input the JSON code.
- For example, input *5* will be received as the string "5".
- To send the integer 5, the input should be *\\5*.
- Uploading a model, and using it, is very similar to what you usually do.
- The exception is that your model will be added before any code is executed.
- That way, you can just execute the same code, but include a model in it.
- The command for this is (instead of the *make_all.py* script)::
- python scripts/execute_model.py http://localhost:8001 test bootstrap/*.alc integration/code/pn_interface.alc integration/code/rpgame.mvc
- This should **NOT** be used to upload all types of models during execution, as it will anonymously create the model.
- The model is only visible in the internals of the Modelverse, and not visible to any user, as it wasn't taken into account in the Modelverse Formalism Graph (in the MvC).
- Fibonacci 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.
- 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
- ----------------
- The simple Fibonacci server is not very relevant to the primary concern of the Modelverse: (meta-)modelling.
- But since we can create whatever kind of server we want, a simple (meta-)modelling server is created.
- The code offers an interface for users to execute modelling operations.
- The interface itself mostly just relays the incoming messages and operations to the internal modelling library.
- The full code is shown in the :download:`MvC Core Algorithm <../core/core_algorithm.alc>`.
- Its behaviour is not too complex, as it relays most operations to the library functions.
- Nonetheless, it implements most operations related to user access control and user management in general.
- When changes need to be made to the interface (*e.g.*, make it computer-readable instead of human-readable), only this file's output statements should be altered.
|