SPARK Documentation

Module Name: SPARK
Organization(s): SRI International
Author/Contact(s): David Morley

This document applies to SPARK version 0.8.x

(DO NOT USE) Useful Python routines for writing modules in SPARK

Out of Date: THIS SECTION IS FOR HISTORICAL PURPOSES ONLY, PLEASE DO NOT USE.

The Python module spark.standard defines some useful things and installs them in the __builtin__ module, so that they are available from all other modules (especially useful when you are in the python debugger).

M.<modulename>
Returns the module object named by <modulename>. So that submodules can be accessed, double-underscores in <modulename> are replaced by ".". For example:
<<< M.spark__agent.dotest()
Is similar to executing:
<<< import spark.agent
<<< spark.agent.dotest()
However, the "M" form does not add spark to the current namespace and being an expression rather than a pair of statements, it can be used in other expressions.
MM.<modulename>
All SPARK python files include
from spark.version import *
Not only does this address Pyhton/Jython 2.1 versus Python 2.2 and 2.3 incompatabilities. It also sets a variable MARK_THIS_MODULE_TO_DROP. MM is like M, but when you use it to access a module, it deletes all python modules that have this variable set. Thus if you are editing some python files and want to make sure that the newest version of each python module will be loaded before you call spark.agent.dotest(), you would use the form:
<<< MM.spark__agent.dotest()
SHOW(x)
Prints all sorts of useful information about x (even if the standard __repr__ and __str__ methods used to print the object raise exceptions and don't work). There is a bit of duplication in the information sometimes - feel free to improve on this if you want :-)
APROPOS("xyz")
APROPOS.xyz
Lists all modules that define something with a name matching *xyz*.
<<< APROPOS.abs
expandtabs ( spark.newgrammar ) = <function expandtabs at 3502050>
expandtabs ( spark.exception ) = <function expandtabs at 4492466>
expandtabs ( yappsrtz ) = <function expandtabs at 3502050>
abspath ( javapath ) = <function abspath at 5825154>
isabs ( javapath ) = <function isabs at 4864516>
expandtabs ( string ) = <function expandtabs at 3502050>
abspath ( os.path ) = <function abspath at 5825154>
isabs ( os.path ) = <function isabs at 4864516>
abs ( __builtin__ ) = <java function abs at 2550821>

The spark.standard module also exports the pdb.pm function and a function ipm. The pdb.pm function puts you into the debugger for the last exception thrown. The ipm function does this for the last exception thrown in an intention thread - quite useful if you want to get at an exception that killed off an intention.

The first thing I do after starting up a Python interpreter is

<<< from spark.standard import *
That way if I get an error in the main thread, I can get to the debugger with:
<<< pm()
Or if I get an error in an intention, I can get to the debugger with:
<<< ipm()
NOTE: The python debugger only works in CPython not Jython.

spark-mode in emacs

spark/src/spark-mode.el contains the definitions for a SPARK-mode in emacs that performs proper syntax and block highlighting and other useful functions for those using emacs to develop SPARK.

To set up spark-mode in emacs.

  1. Download or copy spark-mode.el to a convenient directory.
  2. Add the following to your .emacs file, replacing [DIR] with the directory where spark-mode.el was copied to. If you would prefer to use Jython rather than the C Python implementation, uncomment the third line.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SPARK mode
;; by Mabry Tyson

(load-file "[DIR]")
(add-hook 'spark-mode-hook
        (function (lambda ()
                (font-lock-mode 1))))

python-mode in emacs

If you are editing python code in Emacs, you will find the python-mode extension very useful. It works very well (and is quite stable - the current release, 4.6, has not been modified since 2001). The documentation page for python-mode is:

http://www.python.org/emacs/python-mode/
That page also has links to other Python editing environments.

To set up python-mode in emacs.

  1. Download or copy python-mode.el to a convenient directory.
  2. Add the following to your .emacs file, replacing [DIR] with the directory where python-mode.el was copied to. If you would prefer to use Jython rather than the C Python implementation, uncomment the third line.
(require 'cl)
(pushnew "[DIR]" load-path :test 'equal)
;(setq py-default-interpreter 'jpython)
(autoload 'python-mode "python-mode" "Python major mode" t)
(or (assoc "\\.py$" auto-mode-alist)
    (setq auto-mode-alist 
	  (cons '("\\.py$" . python-mode) auto-mode-alist)) )
(or (assoc "python" interpreter-mode-alist)
    (setq interpreter-mode-alist 
	  (cons '("python" . python-mode) interpreter-mode-alist)))
;;; add these lines if you like color-based syntax highlighting
;;; and don't get it automatically
;(global-font-lock-mode t)
;(setq font-lock-maximum-decoration t) 
The installation instructions also recommend byte compiling python-mode.el:
    C-x C-f [DIR]/python-mode.el RET
    M-x byte-compile-file RET
Python usually includes the current directory in the PYTHONPATH (list of places to look for loading python files). The current directory for the python process is set when you start the interpreter and seems to be set to the directory of whatever file you are editing. So, to start python with the current directory set to SPARK's src directory (usually what you want) - edit the file .../src/interpreter.py, and type C-c ! to start up a python interpreter.