Exemple #1
0
def _pr_str(obj, print_readably=True):
    _r = print_readably
    if types._list_Q(obj):
        return "(" + " ".join(map(lambda e: _pr_str(e,_r), obj)) + ")"
    elif types._vector_Q(obj):                                    
        return "[" + " ".join(map(lambda e: _pr_str(e,_r), obj)) + "]"
    elif types._hash_map_Q(obj):
        ret = []
        for k in obj.keys():
            ret.extend((_pr_str(k), _pr_str(obj[k],_r)))
        return "{" + " ".join(ret) + "}"
    elif type(obj) in types.str_types:
        if len(obj) > 0 and obj[0] == types._u('\u029e'):
            return ':' + obj[1:]
        elif print_readably:
            return '"' + _escape(obj) + '"'
        else:
            return obj
    elif types._nil_Q(obj):
        return "nil"
    elif types._true_Q(obj):
        return "true"
    elif types._false_Q(obj):
        return "false"
    elif types._atom_Q(obj):
        return "(atom " + _pr_str(obj.val,_r) + ")"
    else:
        return obj.__str__()
Exemple #2
0
def _pr_str(obj, print_readably=True):
    _r = print_readably
    if types._list_Q(obj):
        return "(" + " ".join(map(lambda e: _pr_str(e,_r), obj)) + ")"
    elif types._vector_Q(obj):                                    
        return "[" + " ".join(map(lambda e: _pr_str(e,_r), obj)) + "]"
    elif types._hash_map_Q(obj):
        ret = []
        for k in obj.keys():
            ret.extend((_pr_str(k), _pr_str(obj[k],_r)))
        return "{" + " ".join(ret) + "}"
    elif types._string_Q(obj):
        if print_readably:
            return '"' + obj.encode('unicode_escape').replace('"', '\\"') + '"'
        else:
            return obj
    elif types._nil_Q(obj):
        return "nil"
    elif types._true_Q(obj):
        return "true"
    elif types._false_Q(obj):
        return "false"
    elif types._atom_Q(obj):
        return "(atom " + _pr_str(obj.val,_r) + ")"
    else:
        return obj.__str__()
Exemple #3
0
def _pr_str(obj, print_readably=True):
    assert isinstance(obj, MalType)
    _r = print_readably
    if types._list_Q(obj):
        res = []
        for e in obj.values:
            res.append(_pr_str(e,_r))
        return u"(" + u" ".join(res) + u")"
    elif types._vector_Q(obj):
        res = []
        for e in obj.values:
            res.append(_pr_str(e,_r))
        return u"[" + u" ".join(res) + u"]"
    elif types._hash_map_Q(obj):
        ret = []
        for k in obj.dct.keys():
            ret.append(_pr_a_str(k,_r))
            ret.append(_pr_str(obj.dct[k],_r))
        return u"{" + u" ".join(ret) + u"}"
    elif isinstance(obj, MalStr):
        return _pr_a_str(obj.value,_r)
    elif obj is nil:
        return u"nil"
    elif obj is true:
        return u"true"
    elif obj is false:
        return u"false"
    elif types._atom_Q(obj):
        return u"(atom " + _pr_str(obj.get_value(),_r) + u")"
    elif isinstance(obj, MalSym):
        return obj.value
    elif isinstance(obj, MalInt):
        return unicode(str(obj.value))
    elif isinstance(obj, MalFunc):
        return u"#<function>"
    else:
        return u"unknown"
Exemple #4
0
def atom_Q(args):
    return wrap_tf(types._atom_Q(args[0]))