コード例 #1
0
def match_Con(con):
    with mat(con):
        if case(Con(_x, _xs)):
            return _x[0]
        if case(_):
            print '...'
            return None
コード例 #2
0
def matchAndAssign(val):
    with mat(val):
        if case(int):
            return 1
        if case(str):
            return 2
        if case(_x):
            return _x[0]
コード例 #3
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'
コード例 #4
0
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'
コード例 #5
0
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
コード例 #6
0
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
コード例 #7
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