Example #1
0
def test_finding_functions(lisp, cl):
    add = lisp.function("+")
    assert add(1, 2, 3, 4) == 10
    div = lisp.function("/")
    assert div(2, 4) == fractions.Fraction(1, 2)
    assert cl.oddp(5)
    assert cl.cons(5, None) == cl4py.List(5)
    assert cl.remove(5, [1, -5, 2, 7, 5, 9], key=cl.abs) == [1, 2, 7, 9]
    assert cl.mapcar(cl.constantly(4), (1, 2, 3)) == cl4py.List(4, 4, 4)
    assert cl.loop('repeat', 5, 'collect', 42) == List(42, 42, 42, 42, 42)
    assert cl.progn(5, 6, 7, ('+', 4, 4)) == 8
Example #2
0
def test_examples(lisp):
    assert lisp.eval(42) == 42
    assert lisp.eval(("+", 2, 3)) == 5
    assert lisp.eval(('/', ('*', 3, 5), 2)) == fractions.Fraction(15, 2)
    assert lisp.eval(cl4py.List(cl4py.Symbol('STRING='), 'foo', 'bar')) == ()
    assert lisp.eval(cl4py.List(cl4py.Symbol('STRING='), 'foo', 'foo')) == True
    assert lisp.eval(cl4py.Symbol('*PRINT-BASE*', 'COMMON-LISP')) == 10
    assert lisp.eval(('loop', 'for', 'i', 'below', 5, 'collect',
                      'i')) == cl4py.List(0, 1, 2, 3, 4)
    assert lisp.eval(
        ('with-output-to-string', ('stream', ), ('princ', 12, 'stream'),
         ('princ', 34, 'stream'))) == '1234'
Example #3
0
def test_conses(cl, lisp):
    assert lisp.eval(("CONS", 1, 2)) == cl4py.Cons(1, 2)
    lst = lisp.eval(("CONS", 1, ("CONS", 2, ())))
    assert lst == cl4py.List(1, 2)
    assert lst.car == 1
    assert lst.cdr == cl4py.List(2)
    assert list(lst) == [1, 2]
    assert sum(lst) == 3
    assert lisp.eval(('CONS', 1, ('CONS', 2, 3))) == cl4py.DottedList(1, 2, 3)
    twos = cl.cons(2, 2)
    twos.cdr = twos
    assert cl.mapcar(lisp.function("+"), (1, 2, 3, 4),
                     twos) == List(3, 4, 5, 6)
Example #4
0
def test_examples(lisp):
    assert lisp.eval(("+", 2, 3)) == 5
    add = lisp.function("+")
    assert add(1, 2, 3, 4) == 10
    div = lisp.function("/")
    assert div(2, 4) == fractions.Fraction(1, 2)
    assert lisp.eval(cl4py.Symbol("*PRINT-BASE*", "COMMON-LISP")) == 10
    assert lisp.eval(("CONS", 1, 2)) == cl4py.Cons(1, 2)
    lst = lisp.eval(("CONS", 1, ("CONS", 2, ())))
    assert lst == cl4py.List(1, 2)
    assert lst.car == 1
    assert lst.cdr == cl4py.List(2)
    assert list(lst) == [1, 2]
    assert sum(lst) == 3
Example #5
0
def test_finding_functions(cl):
    assert cl.oddp(5)
    assert cl.cons(5, None) == cl4py.List(5)
    assert cl.remove(5, [1, -5, 2, 7, 5, 9], key=cl.abs) == [1, 2, 7, 9]