Package cells
[hide private]
[frames] | no frames]

Package cells
source code

PyCells

PyCells is a port of Ken Tilton's Cells extenstion to Common Lisp. Cells are objects which automatically discover the cells which call them, and notify those cells of changes.

A short example:
>>> import cells
>>> class Rectangle(cells.Model):
...     width = cells.makecell(value=1)
...     ratio = cells.makecell(value=1.618)
...     @cells.fun2cell()
...     def length(self, prev):
...         print "Length updating..."
...         return float(self.width) * float(self.ratio)
... 
>>> r = Rectangle()
Length updating...

>>> r.length
1.6180000000000001

>>> r.width = 5
Length updating...

>>> r.length
8.0899999999999999


Submodules [hide private]
  • cells.cell: Cell, and subclasses of Cell.
  • cells.cellattr: CellAttr, a wrapper for Cell objects within Models
  • cells.family: Family, a specialized Model for networks of Models.
  • cells.model: Support for the Model object, an object in which CellAttrs may be embedded.
  • cells.observer: Classes which deal with observers, bits of code which fire when a Model is updated and updated cells match certain conditions of the observer, such as cell name or statements about the cell's value.
  • cells.synapse: Synapses, cell variants which exist only within RuleCells and which mediate the propogation of another cell's value.

Functions [hide private]
  makecell(rule=None, value=None, unchanged_if=None, celltype=None)
Creates a new cell attribute in a Model.
  fun2cell(unchanged_if=None, celltype=None)
A decorator which creates a new RuleCell using the decorated function as the rule parameter.
  _debug()
Prints debug messages.
  reset()
Resets all of PyCells' globals back to their on-package-import values.

Variables [hide private]
DEBUG Turns on debugging messages for *all* submodules.
_DECO_OFFSET for the debug ' module > ' messages
cellenv Thread-local cell environment variables.

Function Details [hide private]

makecell(rule=None, value=None, unchanged_if=None, celltype=None)

source code 
Creates a new cell attribute in a Model. This attribute may be accessed as one would access a non-cell attribute, and autovivifies itself in the instance upon first access (in Model.__init__).
Parameters:
  • rule - Define a rule which backs this cell. You must only define one of rule or value. Lacking celltype, this creates a RuleCell. This must be passed a callable with the signature f(self, prev) -> value, where self is the model instance the cell is in and prev is the cell's out-of-date value.
  • value - Define a value for this cell. You must only define one of rule or value. Lacking celltype, this creates an InputCell.
  • unchanged_if - Sets a function to determine if a cell's value has changed. For example,
    >>> class A(cells.Model):
    ...     x = cells.makecell(value=1,
    ...                        unchanged_if=lambda n,o: abs(n - o) > 5)
    ...     y = cells.makecell(rule=lambda s,p: s.x * 2)
    ... 
    >>> a = A()
    >>> a.x
    1
    
    >>> a.y
    2
    
    >>> a.x = 3
    >>> a.x
    3
    
    >>> a.y
    6
    
    >>> a.x = 90
    >>> a.x
    3
    
    >>> a.y
    6
    The signature for the passed function is f(old, new) -> bool.
  • celltype - Set the cell type to generate. You must pass rule or value correctly. Refer to cells.cell for available types.
Returns:
CellAttr

fun2cell(unchanged_if=None, celltype=None)

source code 
A decorator which creates a new RuleCell using the decorated function as the rule parameter.
Parameters:
  • unchanged_if - Sets a function to determine if a cell's value has changed. For example,
    >>> class A(cells.Model):
    ...     x = cells.makecell(value=1,
    ...                        unchanged_if=lambda n,o: abs(n - o) > 5)
    ...     y = cells.makecell(rule=lambda s,p: s.x * 2)
    ... 
    >>> a = A()
    >>> a.x
    1
    
    >>> a.y
    2
    
    >>> a.x = 3
    >>> a.x
    3
    
    >>> a.y
    6
    
    >>> a.x = 90
    >>> a.x
    3
    
    >>> a.y
    6
    The signature for the passed function is f(old, new) -> bool.
  • celltype - Set the cell type to generate. You must pass rule or value correctly. Refer to cells.cell for available types.
Returns:
decorator

_debug()

source code 
Prints debug messages.
Returns:
None

reset()

source code 
Resets all of PyCells' globals back to their on-package-import values. This is a pretty dangerous thing to do if you care about the currently-instantiated cells' state, but quite useful while fooling around in an ipython session.
Returns:
None


Variables Details [hide private]

DEBUG

Turns on debugging messages for *all* submodules. This is a whole lot of text, so you'll probably want to use the submodules' DEBUG flags instead
Value:
False                                                                  
      

_DECO_OFFSET

for the debug ' module > ' messages
Value:
9                                                                     
      

cellenv

Thread-local cell environment variables.
Value:
<thread._local object at 0xe290>