<s> from contextlib import contextmanager <EOL> from . util import hashable <EOL> from . dispatch import dispatch <EOL> _global_logic_variables = set ( ) <EOL> _glv = _global_logic_variables <EOL> class Var ( object ) : <EOL> """<STR_LIT>""" <EOL> _id = <NUM_LIT:1> <EOL> def __new__ ( cls , * token ) : <EOL> if len ( token ) == <NUM_LIT:0> : <EOL> token = "<STR_LIT>" % Var . _id <EOL> Var . _id += <NUM_LIT:1> <EOL> elif len ( token ) == <NUM_LIT:1> : <EOL> token = token [ <NUM_LIT:0> ] <EOL> obj = object . __new__ ( cls ) <EOL> obj . token = token <EOL> return obj <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" + str ( self . token ) <EOL> __repr__ = __str__ <EOL> def __eq__ ( self , other ) : <EOL> return type ( self ) == type ( other ) and self . token == other . token <EOL> def __hash__ ( self ) : <EOL> return hash ( ( type ( self ) , self . token ) ) <EOL> var = lambda * args : Var ( * args ) <EOL> vars = lambda n : [ var ( ) for i in range ( n ) ] <EOL> @ dispatch ( Var ) <EOL> def isvar ( v ) : <EOL> return True <EOL> @ dispatch ( object ) <EOL> def isvar ( o ) : <EOL> return not not _glv and hashable ( o ) and o in _glv <EOL> @ contextmanager <EOL> def variables ( * variables ) : <EOL> """<STR_LIT>""" <EOL> old_global_logic_variables = _global_logic_variables . copy ( ) <EOL> _global_logic_variables . update ( set ( variables ) ) <EOL> try : <EOL> yield <EOL> finally : <EOL> _global_logic_variables . clear ( ) <EOL> _global_logic_variables . update ( old_global_logic_variables ) </s>
