예제 #1
0
파일: core.py 프로젝트: jlucangelio/mal
def println(*args):
    s = " ".join([printer.pr_str(arg, False) for arg in args])
    print s
    return None
예제 #2
0
파일: core.py 프로젝트: feigaochn/mal
    # compare the first two parameters and return true if they are the same
    # type and contain the same value. In the case of equal length lists,
    # each element of the list should be compared for equality and if they are
    # the same return true, otherwise false.
    '=': _chain(MalBool, op.eq),
    # '=': lambda a, b: MalBool(type(a) == type(b) and op.eq(a, b)),

    # <, <=, >, and >=:
    # treat the first two parameters as numbers and do the corresponding numeric
    # comparison, returning either true or false.
    '<': _chain(MalBool, op.lt),
    '<=': _chain(MalBool, op.le),
    '>': _chain(MalBool, op.gt),
    '>=': _chain(MalBool, op.ge),

    # string functions
    'pr-str': lambda *args: MalString(
        " ".join(printer.pr_str(arg, print_readably=True)
                 for arg in args)),
    'str': lambda *args: MalString(
        "".join(printer.pr_str(arg, print_readably=False)
                for arg in args)),
    'prn': lambda *args: print(
        MalString(" ".join(printer.pr_str(arg, print_readably=True)
                           for arg in args))) or nil,
    'println': lambda *args: print(
        " ".join(printer.pr_str(arg, print_readably=False)
                 for arg in args)) or nil,
}
예제 #3
0
파일: core.py 프로젝트: jlucangelio/mal
    elif type(e) == list:
        return seq_equals(e, other)
    elif type(e) == maltypes.Vector:
        return seq_equals(e, other)
    else:
        return e == other

ns[maltypes.Symbol("=")] = equals

ns[maltypes.Symbol("<")] = lambda x, y: x < y
ns[maltypes.Symbol("<=")] = lambda x, y: x <= y
ns[maltypes.Symbol(">")] = lambda x, y: x > y
ns[maltypes.Symbol(">=")] = lambda x, y: x >= y

ns[maltypes.Symbol("pr-str")] = lambda *args: " ".join(
        [printer.pr_str(arg, True) for arg in args])

ns[maltypes.Symbol("str")] = lambda *args: "".join(
        [printer.pr_str(arg, False) for arg in args])

def prn(*args):
    s = " ".join([printer.pr_str(arg, True) for arg in args])
    print s
    return None

def println(*args):
    s = " ".join([printer.pr_str(arg, False) for arg in args])
    print s
    return None

ns[maltypes.Symbol("prn")] = prn
예제 #4
0
파일: step5_tco.py 프로젝트: tomdottom/mal
def PRINT(exp):
    return printer.pr_str(exp, True)
예제 #5
0
파일: core.py 프로젝트: alejandrodob/mal
def _println(*args):
    print String(" ".join(map(lambda exp: pr_str(exp, False), args)))
    return None
예제 #6
0
파일: core.py 프로젝트: takushi-m/hyla
def prn(*x):
    print(" ".join([printer.pr_str(v,True) for v in x]))
    return "nil"
예제 #7
0
파일: step9_try.py 프로젝트: dhnam/mal
def print_(print_arr):
    return printer.pr_str(print_arr)
예제 #8
0
파일: core.py 프로젝트: kanaka/mal.workshop
def do_str(*args):
    return "".join(map(lambda exp: printer.pr_str(exp, False), args))
예제 #9
0
def PRINT(mt):
    return printer.pr_str(mt)
예제 #10
0
파일: core.py 프로젝트: kanaka/mal.workshop
def println(*args):
    print(" ".join(map(lambda exp: printer.pr_str(exp, False), args)))
예제 #11
0
파일: core.py 프로젝트: kanaka/mal.workshop
def pr_str(*args):
    return " ".join(map(lambda exp: printer.pr_str(exp, True), args))
예제 #12
0
파일: core.py 프로젝트: kanaka/mal.workshop
def prn(*args):
    print(" ".join(map(lambda exp: printer.pr_str(exp, True), args)))
예제 #13
0
 def test12(self):
     res = printer.pr_str("\\", True)
     exp = "\\\\"
     assert(res == exp), \
         err_str.format(exp, res)
예제 #14
0
 def test11(self):
     res = printer.pr_str("test\\string", True)
     exp = "test\\\\string"
     assert(res == exp), \
         err_str.format(exp, res)
예제 #15
0
def PRINT(code):
    return printer.pr_str(code)
예제 #16
0
파일: step5_tco.py 프로젝트: p7g/mal
def PRINT(in_: t.MalType) -> str:
    return pr_str(in_, print_readably=True)
예제 #17
0
def prn(*args):
    print(" ".join([pr_str(i, print_readably=True) for i in args]))
    return mal_types.MalNil()
예제 #18
0
파일: pymal.py 프로젝트: joostkremers/pymal
def PRINT(data):
    return printer.pr_str(data, print_readably=True)
예제 #19
0
파일: step5_tco.py 프로젝트: feigaochn/mal
def PRINT(exp: MalType) -> str:
    return printer.pr_str(exp, print_readably=True)
예제 #20
0
파일: step9_try.py 프로젝트: koki0702/mymal
rep("(def! not (fn* (a) (if a false true)))", out_print=False)
rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))",
    out_print=False)
#macro
rep("(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw \"odd number of forms to cond\")) (cons 'cond (rest (rest xs)))))))",
    out_print=False)
rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))",
    out_print=False)

if __name__ == '__main__':
    _args = sys.argv[2:]
    repl_env.set('*ARGV*', _MalData('LIST', list(_args)))

    #rep("(def! not (fn* (a) (if a false true)))")
    if len(sys.argv) >= 2:
        path = sys.argv[1]
        rep('(load-file "' + path + '")')
        sys.exit(0)

    while True:
        try:
            x = input('user> ')
            rep(x, repl_env)

        except MalException as e:
            print("Error:", printer.pr_str(e.object))
        except Exception as e:
            print("".join(traceback.format_exception(*sys.exc_info())))
        except KeyboardInterrupt:
            break
예제 #21
0
def PRINT(s):
    return printer.pr_str(s)
예제 #22
0
파일: step9_try.py 프로젝트: koki0702/mymal
def PRINT(ast):
    txt = printer.pr_str(ast)
    return txt
예제 #23
0
def PRINT(mal_type):
    """
    Convert result of mal instructions into string representation.
    """
    return pr_str(mal_type)
예제 #24
0
파일: core.py 프로젝트: kathleenbanawa/mal
def println(*args):
    print(" ".join([printer.pr_str(e, False) for e in args]))
    return MalNil()
예제 #25
0
def PRINT(ast):
    res = printer.pr_str(ast, print_readably=True)
    return res
예제 #26
0
파일: core.py 프로젝트: kathleenbanawa/mal
def mal_str(*args):
    return printer.pr_str(args)
예제 #27
0
def PRINT(code):
    return printer.pr_str(code)
예제 #28
0
def prn(*arg):
    print(printer.pr_str(arg[0], True))
    return Nil()
예제 #29
0
파일: core.py 프로젝트: jlucangelio/mal
def prn(*args):
    s = " ".join([printer.pr_str(arg, True) for arg in args])
    print s
    return None
예제 #30
0
def _str(*arg):
    return "".join(list(map(lambda x: printer.pr_str(x, False), arg)))
예제 #31
0
파일: core.py 프로젝트: koki0702/mymal
def _str(*args):
    ret = []
    for ast in args:
        ret.append(printer.pr_str(ast, False))
    return _MalData("STRING", "".join(ret))
예제 #32
0
def PRINT(exp):
    return pr_str(exp)
예제 #33
0
 is_empty,
 "count":
 lambda x: mal_types.MalNumber(len(x)),
 "=":
 equal,
 "<":
 lambda x, y: mal_types.MalBool(x.data < y.data),
 "<=":
 lambda x, y: mal_types.MalBool(x.data <= y.data),
 ">":
 lambda x, y: mal_types.MalBool(x.data > y.data),
 ">=":
 lambda x, y: mal_types.MalBool(x.data >= y.data),
 "pr-str":
 lambda *args: mal_types.MalString(" ".join(
     [pr_str(i, print_readably=True) for i in args])),
 "str":
 lambda *args: mal_types.MalString("".join(
     [pr_str(i, print_readably=False) for i in args])),
 "prn":
 prn,
 "println":
 println,
 "read-string":
 read_string,
 "slurp":
 slurp,
 "atom":
 atom,
 "atom?":
 is_atom,
예제 #34
0
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--interactive', action='store_true')
parser.add_argument('filename', nargs='?', help='Filename to be executed')
parser.add_argument('prog_args', nargs='*', help='Arguments passed to program')
parser.add_argument('--prompt', nargs='?', help='Prompt to show to user')
parser.add_argument('--disable-header', action='store_true')
args = parser.parse_args()


if __name__ == '__main__':
    arg_to_str = lambda arg: f'"{arg}"'
    rep(f'(def! *ARGV* {"(list " +  " ".join(arg_to_str(arg) for arg in args.prog_args) + ")" })')
    if args.filename is not None:
        rep(f'(def! *FILENAME* "{args.filename}")')
        rep('(load-file *FILENAME*)')
        if not args.interactive:
            exit(0)
    else:
        if not args.disable_header:
            rep("""(println (str "Mal [" *host-language* "]"))""")
    while True:
        inp = input(args.prompt or 'user> ')
        try:
            res = rep(inp)
        except MalException as e:
            print("Error:", pr_str(e))
        except Exception as e:  # compatibility
            print("Error:", e)
        else:
            print(res)
예제 #35
0
파일: core.py 프로젝트: takushi-m/hyla
 ,"*": lambda x,y: x*y
 ,"/": lambda x,y: x/y
 ,"nil": "nil"
 ,"not": lambda x: not ((type(x)==bool and x) or (type(x)!=bool and x!="nil"))
 ,"list": lambda *l: [*l]
 ,"list?": lambda lst: isinstance(lst,list)
 ,"empty?": lambda lst: len(lst)==0
 ,"count": lambda lst: len(lst) if isinstance(lst,(list,tuple)) else 0
 ,"=": lambda x,y: x==y
 ,">": lambda x,y: x>y
 ,"<": lambda x,y: x<y
 ,">=": lambda x,y: x>=y
 ,"<=": lambda x,y: x<=y
 ,"read-string": lambda s: reader.read_str(s.value)
 ,"slurp": lambda fname:maltype.String(readfile(fname))
 ,"pr-str": lambda *x: maltype.String(" ".join([printer.pr_str(v) for v in x]))
 ,"str": lambda *x: maltype.String("".join([printer.pr_str(v,False) for v in x]))
 ,"prn": prn
 ,"println": println
 ,"atom": lambda v:maltype.Atom(v)
 ,"atom?": maltype.atomp
 ,"deref": lambda a:a.value
 ,"reset!": lambda a,v:a.reset(v)
 ,"swap!": lambda a,f,*arg:a.reset(f(a.value,*arg) if not isinstance(f,dict) else f["fn"](a.value,*arg))
 ,"cons": lambda a,lst: [a,*lst]
 ,"concat": concat
 ,"nth": nth
 ,"first": lambda lst:"nil" if len(lst)==0 or lst=="nil" else nth(lst,0)
 ,"rest": rest
 ,"throw": throw
 ,"apply": apply
예제 #36
0
파일: step2_eval.py 프로젝트: DawerG/mal
def PRINT(result):
    output = pr_str(result)
    print(output)
    return
예제 #37
0
파일: core.py 프로젝트: takushi-m/hyla
def println(*x):
    print(" ".join([printer.pr_str(v,False) for v in x]))
    return "nil"
예제 #38
0
def PRINT(output):
    print(printer.pr_str(output))
예제 #39
0
def PRINT(dt):
    return printer.pr_str(dt)
예제 #40
0
def PRINT(expr):
    return printer.pr_str(expr)
예제 #41
0
def PRINT(x):
    return printer.pr_str(x)
예제 #42
0
def PRINT(form):
    return printer.pr_str(form)
예제 #43
0
def PRINT(ast):
    return printer.pr_str(ast)
예제 #44
0
        return []
    else:
        return reduce(lambda x, y: x + y, args)


ns = {
    '+': lambda a, b: a + b,
    '-': lambda a, b: a - b,
    '*': lambda a, b: a * b,
    '/': lambda a, b: int(a / b),
    '<': lambda a, b: a < b,
    '>': lambda a, b: a > b,
    '=': equals,
    '<=': lambda a, b: a <= b,
    '>=': lambda a, b: a >= b,
    'prn': lambda x: pr_str(x),
    'list': list2,
    'list?': lambda x: type(x) is list,
    'count': lambda x: len(x) if x else 0,
    'empty?': lambda x: len(x) == 0,
    'read-string': read_str,
    'pr-str': pr_str,
    'str': do_str,
    'println': println,
    'slurp': slurp,
    'atom': lambda x: Atom(x),
    'atom?': lambda x: isinstance(x, Atom),
    'deref': lambda x: x.val,
    'reset!': reset,
    'swap!': 1,
    'cons': lambda x, y: [x] + y,
예제 #45
0
def PRINT(print_in):
    return printer.pr_str(print_in)
예제 #46
0
def do_str(*args):
    return "".join(map(lambda exp: pr_str(exp, False), args))
예제 #47
0
파일: core.py 프로젝트: alejandrodob/mal
def _str(*args):
    return String("".join(map(lambda exp: pr_str(exp, False), args)))
예제 #48
0
def prn(*args):
    print(" ".join(map(lambda exp: pr_str(exp, True), args)))
    return None
예제 #49
0
def PRINT(mt):
    res = printer.pr_str(mt)
    return res
예제 #50
0
def println(*args):
    print(" ".join(map(lambda exp: pr_str(exp, False), args)))
    return None
예제 #51
0
파일: main.py 프로젝트: takushi-m/hyla
def PRINT(line):
    res = printer.pr_str(line)
    log(str(res),"PRINT")
    return res
예제 #52
0
def PRINT(exp):
    return printer.pr_str(exp)