• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pair.list函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pair.list函数的典型用法代码示例。如果您正苦于以下问题:Python list函数的具体用法?Python list怎么用?Python list使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了list函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: testVarArgs

 def testVarArgs(self):
     self.pe("(define (mylist . args) args)")
     self.assertEquals(parser.parse("(1 2 3)"), self.pe("(mylist 1 2 3)"))
     self.pe("""(define (list2 a b . c)
                   (list a b c))""")
     self.assertEquals(pair.list(1, 2, pair.list()),
                       self.pe("(list2 1 2)"))
开发者ID:EvelynHf,项目名称:basil,代码行数:7,代码来源:test_scheme.py


示例2: OR_handler

def OR_handler(exp):
    """We have to consider three cases:

    (OR)            ===>   #t

    (OR e1)         ===>   e1

    (OR e1 e2 ...)  ===>   (let ((temp-val e1))
                              (IF temp-val
                                  temp-val
                                  (OR e2 ...)))

                    ===>  ((lambda (temp-val)
                              (IF temp-val
                                  temp-val
                                  (OR e2 ...)))
                           e1)
    """
    clauses = and_clauses(exp)
    if pair.length(clauses) == 0:
        return symbol.true
    elif pair.length(clauses) == 1:
        return pair.car(clauses)
    else:
        temporarySymbol = symbol.makeUniqueTemporary()
        lambdaVal = expressions.makeLambda(
            pair.list(temporarySymbol),
            pair.list(expressions.makeIf(temporarySymbol,
                                         temporarySymbol,
                                         makeOr(pair.cdr(clauses)))))
        return expressions.makeApplication(
            lambdaVal, pair.list(pair.car(clauses)))
开发者ID:EvelynHf,项目名称:basil,代码行数:32,代码来源:expander.py


示例3: expandQuasiquotation

def expandQuasiquotation(exp, depth=1):
    """Takes a quasiquoted expression and constructs a new quoted
    expression.

    FIXME: this function is SO evil.  *grin*  Must clean this up.
    """
    if not pair.isList(exp):
        return makeQuoted(exp)
    if isUnquoted(exp):
        if depth == 1:
            return textOfUnquotation(exp)
        else:
            return pair.list(
                Symbol("list"),
                makeQuoted(Symbol("unquote")),
                expandQuasiquotation(textOfUnquotation(exp), depth - 1))
    if isQuasiquoted(exp):
        return pair.list(
            Symbol("list"),
            makeQuoted(Symbol("quasiquote")),
            expandQuasiquotation(textOfUnquotation(exp), depth + 1))
    else:
        return pair.cons(
            Symbol("list"),
            pair.listMap(lambda subexp:
                         expandQuasiquotation(subexp, depth),
                         exp))
开发者ID:EvelynHf,项目名称:basil,代码行数:27,代码来源:expressions.py


示例4: testAnotherQuasiquote

 def testAnotherQuasiquote(self):
     self.pe("(define x 42)")
     self.assertEquals(42, self.pe("x"))
     self.assertEquals(pair.list
                       (Symbol("x"),
                        pair.list(Symbol("quote"),
                                        pair.list(Symbol("x"), 42))),
                       self.pe("`(x '(x ,x))"))
开发者ID:EvelynHf,项目名称:basil,代码行数:8,代码来源:test_scheme.py


示例5: testQuotation

    def testQuotation(self):
        self.assertEquals(pair.list(Symbol("quote"),
                                          Symbol("atom-man")),
                          parse("'atom-man"))
        self.assertEquals(pair.list(Symbol("quasiquote"),
                                          Symbol("istanbul")),
                          parse("`istanbul"))

        self.assertEquals(pair.list(Symbol("unquote"),
                                          Symbol("constantinople")),
                          parse(",constantinople"))
开发者ID:EvelynHf,项目名称:basil,代码行数:11,代码来源:parser.py


示例6: testStressWithSuperNesting

 def testStressWithSuperNesting(self):
     ## An evil test to see if this raises bad errors.
     N = 1000
     bigNestedList = pair.list()
     for ignored in xrange(N-1):
         bigNestedList = pair.list(bigNestedList)
     try:
         self.assertEquals(bigNestedList,
                           parse( "(" * N + ")" * N))
     except RuntimeError, e:
         self.fail(e)
开发者ID:EvelynHf,项目名称:basil,代码行数:11,代码来源:parser.py


示例7: setUp

    def setUp(self):
        ## We set up a VERY minimal environment here for some tests.
        ## We also set the recursion limit to something dreadful to see that
        ## call/cc is doing the right thing.
        ##

        ## Note: these tests directly work with analyzer.eval, and not
        ## through the nicer scheme.AnalyzingInterpreter interface.

        self.env = extendEnvironment(pair.list(Symbol('pi')),
                                     pair.list(3.1415926),
                                     THE_EMPTY_ENVIRONMENT)
        defineVariable(Symbol("#t"), Symbol("#t"), self.env)
        defineVariable(Symbol("#f"), Symbol("#f"), self.env)
        self.old_recursion_limit = sys.getrecursionlimit()
        sys.setrecursionlimit(100)
开发者ID:EvelynHf,项目名称:basil,代码行数:16,代码来源:test_analyzer.py


示例8: schemeDir

 def schemeDir(self, cont, env, args):
     """A quick function to inspect the first frame."""
     if len(args) != 0:
         raise TypeError, ("dir expected at most 0 arguments, got %s" % len(args))
     names = environment.firstFrame(env).keys()
     names.sort()
     return pogo.bounce(cont, pair.list(*names))
开发者ID:EvelynHf,项目名称:basil,代码行数:7,代码来源:scheme.py


示例9: __expr

    def __expr(self, *follow):
        '''
        expr: head binexpr*
            : head binexpr* "." expr
            : head binexpr* ":" expr
            : head binexpr* ":" EOL block
        '''
        head = self.__head(T.DOT, T.DOTS, *follow)
        args = self.match_loop(self.__binexpr, T.DOT, T.DOTS, *follow)
        body = head.append(args)

        if self.peek in follow:
          if len(body) == 1: return body.car() # remove extra parens
          return body

        if self.peek == T.DOT:
          self.match(T.DOT)
          more = self.__expr(*follow)
        elif self.peek == T.DOTS:
          self.match(T.DOTS)
          if self.try_match(T.EOL):
              more = self.__block()
          else:
              more = list(self.__expr(*follow))
        else:
          raise RuntimeError('internal error')

        return body.append(more)
开发者ID:kr,项目名称:sodium,代码行数:28,代码来源:reader.py


示例10: schemeCallcc

    def schemeCallcc(self, cont, env, args):
        analyzedLambdaBody = args[0]

        def c2(val):
            return pogo.bounce(cont, val)

        cont_procedure = expressions.makeContinuationProcedure(c2)
        return analyzer.apply(analyzedLambdaBody, pair.list(cont_procedure), env, cont)
开发者ID:EvelynHf,项目名称:basil,代码行数:8,代码来源:scheme.py


示例11: testQuasiquotation

    def testQuasiquotation(self):
        self.pe("(define one 1)")
        self.pe("(define two 2)")
        self.pe("(define three 3)")
        self.assertEquals(pair.list(Symbol("one"),
                                          Symbol("two"),
                                          3),
                          self.pe("`(one two ,three)"))
        self.assertEquals(pair.list(Symbol("one"),
                                          Symbol("two"),
                                          (pair.list
                                           (Symbol("unquote"),
                                            Symbol("three")))),
                          self.pe("'(one two ,three)"))

        ## this evil case occurs in R5RS
        self.assertEquals(parser.parse("(a `(b ,(+ 1 2) ,(foo 4 d) e) f)"),
                          self.pe("`(a `(b ,(+ 1 2) ,(foo ,(+ 1 3) d) e) f)"))
开发者ID:EvelynHf,项目名称:basil,代码行数:18,代码来源:test_scheme.py


示例12: __unexpr

    def __unexpr(self):
        '''
        unexpr: atom UNOP*
        '''
        expr = self.__atom()
        while self.peek == T.UNOP:
            expr = list(expr, lx.S(self.match(T.UNOP)))

        return expr
开发者ID:kr,项目名称:sodium,代码行数:9,代码来源:reader.py


示例13: __atom

    def __atom(self, *extra):
        '''
        atom : NAME
             : DEC
             : DECF
             : HEX
             : STR
             : HEREDOC
             : "(" expr ")"
             : "[" expr "]"
             : "'" atom
        '''
        if self.peek == T.LPAR:
            self.match(T.LPAR)
            expr = self.__expr(T.RPAR)
            self.match(T.RPAR)
            return expr

        if self.peek == T.LSQU:
            self.match(T.LSQU)
            expr = self.__expr(T.RSQU)
            self.match(T.RSQU)
            return list(lx.S('bracket'), expr)

        if self.peek == T.QUOTE:
            self.match(T.QUOTE)
            atom = self.__atom()
            return list(lx.S('quote'), atom)

        type, lexeme, pos = self.xmatch(T.DEC, T.DECF, T.HEX, T.NAME, T.STR, T.HEREDOC, *extra)
        if type == T.DEC:
            return lx.Integer(lexeme)
        if type == T.HEX:
            return lx.Integer(lexeme, 16)
        if type == T.NAME:
            return lx.S(lexeme)
        if type == T.STR:
            return lx.String(unescape(lexeme[1:-1], pos)).setpos(pos)
        if type == T.DECF:
            return lx.Decimal(lexeme)
        if type == T.HEREDOC:
            return lx.ForeignString(lexeme).setpos(pos)
        return lx.S(lexeme)
开发者ID:kr,项目名称:sodium,代码行数:43,代码来源:reader.py


示例14: __head

    def __head(self, *follow):
        '''
        head:
            : BINOP UNOP* [BINOP]
            : atom UNOP* [BINOP]
        '''
        if self.peek in follow: return nil

        head = self.__atom(T.BINOP)

        if self.peek not in (T.BINOP, T.UNOP): return list(head)

        while self.peek in (T.UNOP):
          head = list(head, lx.S(self.match(T.UNOP)))

        if self.peek in (T.BINOP):
          head = list(head, lx.S(self.match(T.BINOP)))

        return head
开发者ID:kr,项目名称:sodium,代码行数:19,代码来源:reader.py


示例15: evalRands

def evalRands(exps, env, cont):
    """Given a list of expressions, returns a new list containing the
    values of evaluating each on of them.  If the continuation is
    given, then calls cont() on the evaluated operands instead."""
    def c1(head_val):
        def c2(tail_val):
            return pogo.bounce(cont, pair.cons(head_val, tail_val))
        return evalRands(expressions.restOperands(exps), env, c2)
    if expressions.isNoOperands(exps):
        return pogo.bounce(cont, pair.list())
    return teval(expressions.firstOperand(exps), env, c1)
开发者ID:EvelynHf,项目名称:basil,代码行数:11,代码来源:evaluator.py


示例16: __binexpr

    def __binexpr(self):
        '''
        binexpr: unexpr
               : unexpr BINOP binexpr
        '''
        left = self.__unexpr()
        if self.peek != T.BINOP: return left

        message = lx.S(self.match(T.BINOP))
        right = self.__binexpr()
        return list(left, message, right)
开发者ID:kr,项目名称:sodium,代码行数:11,代码来源:reader.py


示例17: c

 def c(expr):
     return pogo.bounce(cont, pair.list(Symbol(quoteType), expr))
开发者ID:EvelynHf,项目名称:basil,代码行数:2,代码来源:parser.py


示例18: makeQuoted

def makeQuoted(exp):
    return pair.list(Symbol("quote"), exp)
开发者ID:EvelynHf,项目名称:basil,代码行数:2,代码来源:expressions.py


示例19: constructEvilNestedExpression

 def constructEvilNestedExpression(self, n):
     result = pair.list()
     for i in xrange(n-1):
         result = pair.list(result)
     return result
开发者ID:EvelynHf,项目名称:basil,代码行数:5,代码来源:expressions.py


示例20: testLists

 def testLists(self):
     self.assertEquals(pair.list(1, 2), parse("(1 2)"))
     self.assertEquals(pair.list(1, 2, pair.list(3), 4),
                       parse("(1 2 (3) 4)"))
     self.assertEquals(pair.list(pair.list(pair.list())),
                                       parse("((()))"))
开发者ID:EvelynHf,项目名称:basil,代码行数:6,代码来源:parser.py



注:本文中的pair.list函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python actions.ActionQueue类代码示例发布时间:2022-05-27
下一篇:
Python paho_test.gen_connect函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap