A dirty trick to allow side effects in expressions

Assignement takes place when method bind of the expression is called. Assigned variables are then stored in the Substitution passed to bind. This is useful in some cases when you want to repeat a computation in several output arcs: you do it once in the guard and then use the bounded variable on the output arcs.

>>> import snakes.plugins
>>> snakes.plugins.load('let', 'snakes.nets', 'snk')
<module ...>
>>> from snk import *
>>> n = PetriNet('n')
>>> t = Transition('t', Expression('x is not None and let("egg, spam = iter(str(foo))", foo=42, __raise__=True)'))
>>> n.add_transition(t)
>>> n.add_place(Place('p', [dot]))
>>> n.add_input('p', 't', Variable('x'))
>>> t.modes() == [Substitution(x=dot, foo=42, egg='4', spam='2')]
True
Warning: use with care, sides effects are nasty tricks, you may get unexpected results while playing with let
Call API

Class DropLet

class DropLet (ast.NodeTransformer) :

Method DropLet.__init__

def __init__ (self, names) :

Method DropLet.visit_Call

def visit_Call (self, node) :

Class DropTrue

class DropTrue (ast.NodeTransformer) :

Method DropTrue.visit_BoolOp

def visit_BoolOp (self, node) :

Function unlet

def unlet (expr, *names) :

Class MakeLet

class MakeLet (object) :

Method MakeLet.__init__

def __init__ (self, globals) :

Method MakeLet.match

def match (self, match, binding) :

Method MakeLet.__call__

def __call__ (__self__, __match__=None, __raise__=False, **args) :

Extensions

Class PetriNet

class PetriNet (module.PetriNet) :

Method PetriNet.__init__

def __init__ (self, name, **args) :