def match_Con(con): with mat(con): if case(Con(_x, _xs)): return _x[0] if case(_): print '...' return None
def matchAndAssign(val): with mat(val): if case(int): return 1 if case(str): return 2 if case(_x): return _x[0]
def match_recur(num): with mat(num): if case(0): return 0 if case(com(int, lambda x: x > 0)): return num + match_recur(num - 1) if case(_): print 'recurssion matched failed'
def match_Person(p): with mat(p): if case(obj(Police)): return 'police' if case(obj(Student)): return 'student' if case(obj(Person)): return 'person'
def matchAndAssignCond(val): with mat(val): if case(Con(_x, _xs)) and cond(_x[0] > 5, _xs[0] != None): return 1 if case(Con(_x, _xs)) and cond(_x[0] < 5, _xs[0] == None): return 2 if case(_): return 3 return 4
def sum(con): with mat(con): if case(Con(_x, None)): return _x[0] if case(Con(_x, _xs)): return _x[0] + sum(_xs[0]) if case(_): print 'does not match with anything' return 0
def match_number(num): counter = 0 with mat(num): if case(int): counter += 1 if case(5): counter += 2 if case(4): counter += 4 if case(_): counter += 8 return counter