예제 #1
0
def stdenv_defmacro_test():
    env = make_stdenv()
    called = 0
    def f(e):
        nonlocal called
        called += 1
        return SNode('num', 5)
    env.define('f', SNode('function', f))
    seval('(~defmacro twice (a) `(+ ,a ,a))', env)
    eq_(seval_strip('(~twice (f))', env), 10)
    eq_(called, 2)
예제 #2
0
def stdenv_append_test():
    eq_(seval_strip('(~append (1 2) (3 4) (5))', make_stdenv()), (1, 2, 3, 4, 5))
예제 #3
0
def stdenv_defun_test():
    env = make_stdenv()
    seval('(~defun add (a b) (+ a b))', env)
    eq_(seval_strip('(add 1 2)', env), 3)
예제 #4
0
def stdenv_apply_test():
    eq_(seval_strip('(apply + `(2 3))', make_stdenv()), 5)
예제 #5
0
def stdenv_restargs_test():
    eq_(seval_strip('((~lambda (x . y) (apply + y)) 1 2 3)', make_stdenv()), 5)
예제 #6
0
def stdenv_eval_test():
    eq_(seval_strip('(eval `(+ 1 1) (this-env))', make_stdenv()), 2)
예제 #7
0
def seval_env_test():
    env = SEnvironment()
    env.define('x', SNode('num', 5))
    eq_(seval_strip('x', env), 5)
예제 #8
0
def stdenv_head_test():
    eq_(seval_strip("(head '(1 2 3))", make_stdenv()), 1)
예제 #9
0
def stdenv_tail_test():
    eq_(seval_strip("(tail '(1 2 3))", make_stdenv()), (2, 3))
예제 #10
0
def stdenv_quote_quote_test():
    eq_(seval_strip('(~quote (~quote (1 2 3)))', make_stdenv()), ('~', 'quote', (1, 2, 3)))
예제 #11
0
def stdenv_cons_nil_test():
    eq_(seval_strip('(cons 1 (cons 2 nil))', make_stdenv()), (1, 2))
예제 #12
0
def stdenv_lambda_with_args_test():
    eq_(seval_strip('((~lambda (x) x) 5)', make_stdenv()), 5)
예제 #13
0
def stdenv_lambda_test():
    eq_(seval_strip('((~lambda () 5))', make_stdenv()), 5)
예제 #14
0
def seval_num_test():
    eq_(seval_strip('3'), 3)
예제 #15
0
def seval_unquote_splice_test():
    eq_(seval_strip("`(1 ,@'(2))", make_stdenv()), (1, 2))
예제 #16
0
def stdenv_quasiquote_test():
    eq_(seval_strip('`(1 2)', make_stdenv()), (1, 2))
예제 #17
0
def stdenv_if_test():
    eq_(seval_strip('(~if (= 1 1) 1 0)', make_stdenv()), 1)
예제 #18
0
def stdenv_unquote_test():
    eq_(seval_strip('`(1 ,(+ 1 1))', make_stdenv()), (1, 2))
예제 #19
0
def stdenv_define_test():
    env = make_stdenv()
    seval_strip('(~define x 5)', env)
    eq_(env.lookup('x'), SNode('num', 5))
예제 #20
0
def seval_funcall_test():
    eq_(seval_strip('(+ 3 2)', make_stdenv()), 5)