예제 #1
0
def extend_env(env, names, values):
    if is_pair(names) and is_pair(values):
        return VariableEnv(extend_env(env, names.cdr, values.cdr), names.car,
                           values.car)
    elif is_null(names) and is_null(values):
        return env
    elif is_symbol(names):
        return VariableEnv(env, names, values)
    else:
        raise TypeError("Arity mismatch")
    def add_dict(self,
                 nCodeType,
                 sTypeName,
                 sCodeName,
                 nSort=None,
                 sExtendInfo=None,
                 nFlag=1,
                 sCodeEnumName=None):
        try:
            # 获取该字典类型总条数
            lsCode = Dictionary().query.\
                filter(Dictionary.CodeType == nCodeType).\
                all()
            # 获取该字典类型名的字段是否存在
            lsTypeName = Dictionary().query.filter(
                Dictionary.TypeName == sTypeName).all()

            nCount = len(lsCode)
            objDict = Dictionary()

            objDict.CodeType = nCodeType
            if nFlag:
                objDict.Flag = nFlag
            else:
                objDict.Flag = 1

            if not is_null(sCodeName):
                objDict.CodeName = sCodeName
            if not is_null(nSort):
                objDict.Sort = nSort
            if not is_null(sExtendInfo):
                objDict.ExtendInfo = sExtendInfo
            if not is_null(sCodeEnumName):
                objDict.CodeEnumName = sCodeEnumName
            if nCount:
                objDict.CodeNo = nCount + 1
                objDict.TypeName = lsCode[0].TypeName
            else:
                objDict.CodeNo = 1
                if not sTypeName:
                    return FuncResult(fail='请输入类型名称sTypeName')
                if len(lsTypeName):
                    return FuncResult(fail='类型名称' + sTypeName + '已存在!')
                objDict.TypeName = sTypeName

            # 保存更改到数据库
            objDict.save()
        except Exception, ce:
            return FuncResult(fail=ce)
예제 #3
0
def extend(env, variables, values):
    if is_pair(variables):
        if is_pair(values):
            return cons(cons(variables.car, values.car),
                        extend(env, variables.cdr, values.cdr))
        else:
            raise ValueError("Too few values")
    elif is_null(variables):
        if is_null(values):
            return env
        else:
            raise ValueError("Too many values")
    elif is_symbol(variables):
        return cons(cons(variables, values), env)
    else:
        raise RuntimeError("Branch should be unreachable")
    def update_dict(self, nCodeID, nDictType, sCodeName, nFlag):
        objDict = Dictionary().query.\
            filter(Dictionary.CodeID == nCodeID).\
            first()

        if objDict:
            if objDict.Flag == 0:
                return FuncResult(msg='无查询结果!')

            if not is_null(nDictType):
                objDict.CodeType = nDictType

            if not is_null(sCodeName):
                objDict.CodeName = sCodeName

            if not is_null(nFlag):
                objDict.Flag = nFlag

            # 保存更改到数据库
            objDict.save()

        return FuncResult(success=True, msg='操作成功!', data='')
예제 #5
0

def primitive(name, value, vs, arity, k):
    if arity == length(vs):
        return k.resume(value(vs))
    else:
        raise TypeError("incorrect arity {} {}".format(name, vs))

GLOBAL_ENV = NullEnv()
definitial('f')
definitial('foo')
definitial('bar')
definitial('x')
definitial('y')
definitial('z')
defprimitive('null?', lambda args: is_null(args.car), 1)
defprimitive('cons', lambda args: cons(args.car, args.cadr), 2)
defprimitive('car', lambda args: args.caar, 1)
defprimitive('cdr', lambda args: args.cdar, 1)
defprimitive('+', lambda args: args.car + args.cadr, 2)
defprimitive('-', lambda args: args.car - args.cadr, 2)
defprimitive('*', lambda args: args.car * args.cadr, 2)
defprimitive('/', lambda args: args.car / args.cadr, 2)
definitial('println', Primitive('println', lambda args, r, k: k.resume(
    print() if is_null(args) else print(str(args)[1:-1]))))

definitial(
    'call/cc',
    Primitive(
        'call/cc',
        lambda vs, r, k: vs.car.invoke(cons(k, Nil), r, k) if length(
예제 #6
0
def primitive(name, value, vs, arity, k):
    if arity == length(vs):
        return k.resume(value(vs))
    else:
        raise TypeError("incorrect arity {} {}".format(name, vs))


GLOBAL_ENV = NullEnv()
definitial('f')
definitial('foo')
definitial('bar')
definitial('x')
definitial('y')
definitial('z')
defprimitive('null?', lambda args: is_null(args.car), 1)
defprimitive('cons', lambda args: cons(args.car, args.cadr), 2)
defprimitive('car', lambda args: args.caar, 1)
defprimitive('cdr', lambda args: args.cdar, 1)
defprimitive('+', lambda args: args.car + args.cadr, 2)
defprimitive('-', lambda args: args.car - args.cadr, 2)
defprimitive('*', lambda args: args.car * args.cadr, 2)
defprimitive('/', lambda args: args.car / args.cadr, 2)
definitial(
    'println',
    Primitive(
        'println', lambda args, r, k: k.resume(print()
                                               if is_null(args) else print(
                                                   str(args)[1:-1]))))

definitial(
예제 #7
0
definitial('bar')
definitial('x')
definitial('y')
definitial('z')
defprimitive('cons', lambda args: cons(args.car, args.cadr), 2)
defprimitive('car', lambda args: args.caar, 1)
defprimitive('cdr', lambda args: args.cdar, 1)
defprimitive('+', lambda args: args.car + args.cadr, 2)
defprimitive('-', lambda args: args.car - args.cadr, 2)
defprimitive('*', lambda args: args.car * args.cadr, 2)
defprimitive('/', lambda args: args.car / args.cadr, 2)
definitial(
    'println',
    Primitive(
        'println', lambda args, r, k: k.resume(print()
                                               if is_null(args) else print(
                                                   str(args)[1:-1]))))

definitial(
    'call/cc',
    Primitive(
        'call/cc', lambda vs, r, k: vs.car.invoke(cons(k, Nil), r, k)
        if length(vs) == 1 else wrong(
            TypeError("incorrect arity {} {}".format('call/cc', vs)))))

definitial('apply',
           Primitive('apply', lambda vs, r, k: vs.car.invoke(vs.cadr, r, k)))


def wrong(e):
    raise e