Getting Started
Installation
The Python integration of FCG (aka PyFCG) is distributed as a pip-installable package. To install this package from PyPI, run the following command.
$ pip install pyfcg
Use
Once pip-installed, PyFCG can readily be imported as a module into Python programs.
It is customary to define fcg as an alias for the PyFCG module, so that all functionality is available within the fcg namespace (functions and variables are thereby prefixed with fcg.)
You initialise PyFCG as follows:
>>> import pyfcg as fcg
>>> fcg.init()
Many FCG functions depend on the fcg-go precompiled binary, which you loaded (or download if necessary) by calling the init() function.
On macOS, you will need to accept opening the application bundle by clicking “open” in the popup window.
Example: Creating an FCG Agent
The Agent class will usually be your main entry point.
The idea is that an agent has a grammar (of type Grammar), which in turn holds constructions (of type Construction).
In PyFCG, a grammar will always be tied to an agent.
Upon creation, an agent is automatically initialised with an empty grammar, i.e. a grammar that holds zero constructions.
>>> demo_agent = fcg.Agent()
>>> demo_agent
<Agent: agent (id: agent-42) ~ 0 constructions>
>>> demo_agent.grammar.size()
0