Update documentation after 0.1.1 release
[clnl] / docs / DocsMain.md
diff --git a/docs/DocsMain.md b/docs/DocsMain.md
new file mode 100644 (file)
index 0000000..94e57ac
--- /dev/null
@@ -0,0 +1,176 @@
+# Package CLNL
+
+Main CLNL package
+
+The entry point for general purpose clnl startup, as well as the place that ties all the parts together into a cohesive whole.
+
+## Contents
+
+* **variable [\*model\-package\*](#variable-model-package)** - _*model-package*_ is used for interning symbols as a NetLogo code gets compiled.
+* **function [boot](#function-boot)** - _boot_ does exactly that, boots the clnl system in a clean state.  The seed is set so that multiple runs will evaluate to the same.
+* **function [model->multi-form-lisp](#function-model->multi-form-lisp)** - _model->multi-form-lisp_ takes a model and returns a multi form lisp program, that when executed, sets up the model.  Procedures map to defuns, globals to defvars, etc.  This can be output to load up quickly later.  A function named by _boot-fn_ will be set for booting the program.
+* **function [model->single-form-lisp](#function-model->single-form-lisp)** - _model->single-form-lisp_ takes a model and returns a lisp program as a single form, that when executed runs the model.  The _seed_ passed in is used to start the clnl-random RNG.
+* **function [nlogo->lisp](#function-nlogo->lisp)** - _nlogo->lisp_ takes a stream _str_ and returns a multi form lisp program, that when executed, sets up the model.  See MODEL->MULTI-FORM-LISP for more information.
+* **function [run](#function-run)** - _run_ starts up the CLNL system.
+* **function [run-commands](#function-run-commands)** - _run-commands_ will take NetLogo commands, put them through the various stages need to turn them into Common Lisp code, and run it.
+* **function [run-reporter](#function-run-reporter)** - _run-reporter_ will take a NetLogo _reporter_, put it through the various stages need to turn them into Common Lisp code, run it, and return the _result_.
+
+## Variable \*MODEL\-PACKAGE\*
+
+#### Value Type:
+
+a package
+
+#### Initial Value:
+
+The package named by :clnl-default-model-package
+
+#### Description:
+
+_*model-package*_ is used for interning symbols as a NetLogo code gets compiled.
+
+:clnl-default-model-package is used because it's set up to shadow common overlaps between the :cl package and netlogo programs, most notably GO.  When you set this to a package of your choosing, be aware of those overlaps in the case that use :use :common-lisp
+
+Any local symbols are interned in this package, for use either by other code, or in order to have all symbols interned in the same placakge.  This is also the package in which a model should be run, whether by clnl code or independently.
+
+## Function **BOOT**
+
+#### Syntax:
+
+**boot** _&optional_ _file_ _headless-mode_ => _result_
+
+#### Arguments and Values:
+
+_file_---nlogo file with which to initialize state  
+_headless-mode_---a boolean, defaults to nil  
+_result_---undefined  
+
+#### Description:
+
+_boot_ does exactly that, boots the clnl system in a clean state.  The seed is set so that multiple runs will evaluate to the same.
+
+When _file_ is not provided, a default model is used.
+
+When _headless-mode_ is set to nil, the opengl interface is initialized. Otherwise, the model will run headlessly, with no view.
+
+## Function **MODEL->MULTI-FORM-LISP**
+
+#### Syntax:
+
+**model->multi-form-lisp** _model_ _boot-fn_ _&key_ _seed_ _initialize-interface_ _netlogo-callback-fn_ => _forms_
+
+#### Arguments and Values:
+
+_model_---A valid model  
+_boot-fn_---A function name  
+_seed_---An integer, defaults to 15  
+_initialize-interface_---A boolean  
+_netlogo-callback-fn_---a symbol  
+_forms_---A list of common lisp form  
+
+#### Description:
+
+_model->multi-form-lisp_ takes a model and returns a multi form lisp program, that when executed, sets up the model.  Procedures map to defuns, globals to defvars, etc.  This can be output to load up quickly later.  A function named by _boot-fn_ will be set for booting the program.
+
+The _seed_ passed in is used to start the clnl-random RNG.
+
+_initialize-interface_, when non nil, leads to initialization code for the opengl interface being included.
+
+_netlogo-callback-fn_ is a symbol that will be defined as a function to be called to execute code in the running netlogo instance.
+
+## Function **MODEL->SINGLE-FORM-LISP**
+
+#### Syntax:
+
+**model->single-form-lisp** _model_ _&key_ _seed_ _initialize-interface_ _netlogo-callback_ => _form_
+
+#### Arguments and Values:
+
+_model_---A valid model  
+_seed_---An integer, defaults to 15  
+_initialize-interface_---A boolean  
+_netlogo-callback_---A function of one argument, or a symbol  
+_form_---A common lisp form  
+
+#### Description:
+
+_model->single-form-lisp_ takes a model and returns a lisp program as a single form, that when executed runs the model.  The _seed_ passed in is used to start the clnl-random RNG.
+
+_initialize-interface_, when non nil, leads to initialization code for the opengl interface being included.
+
+_netlogo-callback_ is a function that when called with a single argument, a function that when called with netlogo code, will compile and run that code in the environment of the model.
+
+Of note, all globals defined either in the model code or via the widgets are declared special in order to remain in the lexical environment for EVAL.
+
+## Function **NLOGO->LISP**
+
+#### Syntax:
+
+**nlogo->lisp** _str_ _pkg-symb_ _boot-fn_ _&key_ _seed_ _initialize-interface_ _netlogo-callback-fn_ => _forms_
+
+#### Arguments and Values:
+
+_str_---A stream holding an nlogo file  
+_pkg-symb_---A symbol for the generated package  
+_boot-fn_---A function name  
+_seed_---An integer, defaults to 15  
+_initialize-interface_---A boolean  
+_netlogo-callback-fn_---a symbol  
+_forms_---A list of common lisp form  
+
+#### Description:
+
+_nlogo->lisp_ takes a stream _str_ and returns a multi form lisp program, that when executed, sets up the model.  See MODEL->MULTI-FORM-LISP for more information.
+
+_nlogo->lisp_ does extra work of setting up the package to be named by _pkg-symb_ in order to correctly shadow common lisp functions.
+
+It will also change the current package to the one created for the model named by _pkg-symb_.
+
+#### Examples:
+
+```(with-open-file (str "Wolf Sheep Predation.nlogo") (nlogo->lisp str :wolfsheep 'boot))``` => ```(forms)```  
+
+## Function **RUN**
+
+#### Syntax:
+
+**run** _&optional_ _file_ => _result_
+
+#### Arguments and Values:
+
+_file_---nlogo file with which to initialize  
+_result_---undefined, the system terminates at the end of the loop  
+
+#### Description:
+
+_run_ starts up the CLNL system.
+
+## Function **RUN-COMMANDS**
+
+#### Syntax:
+
+**run-commands** _cmds_ => _result_
+
+#### Arguments and Values:
+
+_cmds_---A string that may have one more NetLogo commands  
+_result_---undefined  
+
+#### Description:
+
+_run-commands_ will take NetLogo commands, put them through the various stages need to turn them into Common Lisp code, and run it.
+
+## Function **RUN-REPORTER**
+
+#### Syntax:
+
+**run-reporter** _reporter_ => _result_
+
+#### Arguments and Values:
+
+_reporter_---A string that should have only one reporter  
+_result_---The value reported by the NVM  
+
+#### Description:
+
+_run-reporter_ will take a NetLogo _reporter_, put it through the various stages need to turn them into Common Lisp code, run it, and return the _result_.