コード例 #1
0
 def type(self, val):
     "Get the Python type of a Scheme value."
     if expressions.isCompoundProcedure(val):
         return schemepy.types.Lambda
     if expressions.isPrimitiveProcedure(val):
         fun = expressions.primitiveImplementation(val)
         orig = fun.__dict__.get("_orig", None)
         if orig and callable(orig):
             return types.FunctionType
         return schemepy.types.Lambda
     if symbol.isSymbol(val):
         if val == symbol.true or val == symbol.false:
             return bool
         return schemepy.types.Symbol
     if pair.isNull(val):
         return list
     if isAList(val):
         return dict
     if pair.isList(val):
         return list
     if pair.isPair(val):
         return schemepy.types.Cons
     t = type(val)
     if t not in (int, complex, float, long, str, unicode):
         return object
     return t
コード例 #2
0
ファイル: pyscheme.py プロジェクト: stjordanis/schemepy-1
 def type(self, val):
     "Get the Python type of a Scheme value."
     if expressions.isCompoundProcedure(val):
         return schemepy.types.Lambda
     if expressions.isPrimitiveProcedure(val):
         fun = expressions.primitiveImplementation(val)
         orig = fun.__dict__.get("_orig", None)
         if orig and callable(orig):
             return types.FunctionType
         return schemepy.types.Lambda
     if symbol.isSymbol(val):
         if val == symbol.true or val == symbol.false:
             return bool
         return schemepy.types.Symbol
     if pair.isNull(val):
         return list
     if isAList(val):
         return dict
     if pair.isList(val):
         return list
     if pair.isPair(val):
         return schemepy.types.Cons
     t = type(val)
     if t not in (int, complex, float, long, str, unicode):
         return object
     return t
コード例 #3
0
ファイル: expressions.py プロジェクト: EvelynHf/basil
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))
コード例 #4
0
 def t_expand(self, expr, cont):
     """Trampolined expander."""
     if not pair.isList(expr):
         return pogo.bounce(cont, expr)
     
     handler = self._handlers.get(self.get_keyword_tag(expr), None)
     if handler:
         ## expand, and recursively call expansion again.
         return pogo.bounce(self.t_expand, handler(expr), cont)
     elif self.is_special_form(expr):
         return pogo.bounce(self.t_expand_special_form, expr, cont)
     else:
         ## We recursively expand all the subexpressions by mapping
         ## t_expand() across the elements.
         return pogo.bounce(pair.c_listMap, self.t_expand, expr, cont)
コード例 #5
0
ファイル: pyscheme.py プロジェクト: stjordanis/schemepy-1
 def fromscheme(self, val, shallow=False):
     "Convert a Scheme value to a Python value."
     if expressions.isCompoundProcedure(val):
         return schemepy.types.Lambda(val, self, shallow)
     if expressions.isPrimitiveProcedure(val):
         fun = expressions.primitiveImplementation(val)
         orig = fun.__dict__.get("_orig", None)
         if orig and callable(orig):
             return orig
         return schemepy.types.Lambda(val, self, shallow)
     if symbol.isSymbol(val):
         if val == symbol.true:
             return True
         if val == symbol.false:
             return False
         return schemepy.types.Symbol(str(val))
     if pair.isNull(val):
         return []
     if isAList(val):
         dic = {}
         while not pair.isNull(val):
             el = pair.car(val)
             key = self.fromscheme(pair.car(el))
             value = pair.cdr(el)
             if not shallow:
                 value = self.fromscheme(value)
             dic[key] = value
             val = pair.cdr(val)
         return dic
     if pair.isList(val):
         lst = []
         while not pair.isNull(val):
             el = pair.car(val)
             if not shallow:
                 el = self.fromscheme(el)
             lst.append(el)
             val = pair.cdr(val)
         return lst
     if pair.isPair(val):
         car = pair.car(val)
         cdr = pair.cdr(val)
         if not shallow:
             car = self.fromscheme(car)
             cdr = self.fromscheme(cdr)
         return schemepy.types.Cons(car, cdr)
     return val
コード例 #6
0
 def fromscheme(self, val, shallow=False):
     "Convert a Scheme value to a Python value."
     if expressions.isCompoundProcedure(val):
         return schemepy.types.Lambda(val, self, shallow)
     if expressions.isPrimitiveProcedure(val):
         fun = expressions.primitiveImplementation(val)
         orig = fun.__dict__.get("_orig", None)
         if orig and callable(orig):
             return orig
         return schemepy.types.Lambda(val, self, shallow)
     if symbol.isSymbol(val):
         if val == symbol.true:
             return True
         if val == symbol.false:
             return False
         return schemepy.types.Symbol(str(val))
     if pair.isNull(val):
         return []
     if isAList(val):
         dic = {}
         while not pair.isNull(val):
             el = pair.car(val)
             key = self.fromscheme(pair.car(el))
             value = pair.cdr(el)
             if not shallow:
                 value = self.fromscheme(value)
             dic[key] = value
             val = pair.cdr(val)
         return dic
     if pair.isList(val):
         lst = []
         while not pair.isNull(val):
             el = pair.car(val)
             if not shallow:
                 el = self.fromscheme(el)
             lst.append(el)
             val = pair.cdr(val)
         return lst
     if pair.isPair(val):
         car = pair.car(val)
         cdr = pair.cdr(val)
         if not shallow:
             car = self.fromscheme(car)
             cdr = self.fromscheme(cdr)
         return schemepy.types.Cons(car, cdr)
     return val
コード例 #7
0
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))
コード例 #8
0
ファイル: builtins.py プロジェクト: cahirwpz/tpserver-py
def schemeListQuestion(a): return schemeBooleanize(pair.isList(a))
def schemeNullQuestion(a): return schemeBooleanize(pair.isNull(a))
コード例 #9
0
def isTaggedList(exp, tag):
    """Returns true if the expression is tagged with the 'tag'."""
    if pair.isList(exp) and pair.length(exp) > 0:
        return pair.car(exp) == tag
    return 0
コード例 #10
0
def isApplication(exp):
    return pair.isList(exp)
コード例 #11
0
def schemeListQuestion(a): return schemeBooleanize(pair.isList(a))
def schemeNullQuestion(a): return schemeBooleanize(pair.isNull(a))
コード例 #12
0
ファイル: expressions.py プロジェクト: EvelynHf/basil
def isTaggedList(exp, tag):
    """Returns true if the expression is tagged with the 'tag'."""
    if pair.isList(exp) and pair.length(exp) > 0:
        return pair.car(exp) == tag
    return 0
コード例 #13
0
ファイル: expressions.py プロジェクト: EvelynHf/basil
def isApplication(exp):
    return pair.isList(exp)