sync from Atlas

This commit is contained in:
Luciano Ramalho
2021-09-20 10:37:26 -03:00
parent 6527037ae7
commit 2f2f87d4fb
16 changed files with 1730 additions and 115 deletions

View File

@@ -2,16 +2,12 @@
Doctests for `parse`
--------------------
# tag::PARSE_ATOM[]
# tag::PARSE[]
>>> from lis import parse
>>> parse('1.5')
1.5
>>> parse('ni!')
'ni!'
# end::PARSE_ATOM[]
# tag::PARSE_LIST[]
>>> parse('(gcd 18 45)')
['gcd', 18, 45]
>>> parse('''
@@ -21,15 +17,15 @@ Doctests for `parse`
... ''')
['define', 'double', ['lambda', ['n'], ['*', 'n', 2]]]
# end::PARSE_LIST[]
# end::PARSE[]
Doctest for `Environment`
-------------------------
# tag::ENVIRONMENT[]
>>> from lis import Environment
>>> outer_env = {'a': 0, 'b': 1}
>>> inner_env = {'a': 2}
>>> outer_env = {'a': 0, 'b': 1}
>>> env = Environment(inner_env, outer_env)
>>> env['a'] = 111 # <1>
>>> env['c'] = 222
@@ -64,11 +60,11 @@ KeyError: 'ni!'
# tag::EVAL_QUOTE[]
>>> evaluate(parse('(quote no-such-name)'), {})
>>> evaluate(parse('(quote no-such-name)'), standard_env())
'no-such-name'
>>> evaluate(parse('(quote (99 bottles of beer))'), {})
>>> evaluate(parse('(quote (99 bottles of beer))'), standard_env())
[99, 'bottles', 'of', 'beer']
>>> evaluate(parse('(quote (/ 10 0))'), {})
>>> evaluate(parse('(quote (/ 10 0))'), standard_env())
['/', 10, 0]
# end::EVAL_QUOTE[]
@@ -156,11 +152,12 @@ gcd_src = """
(if (= n 0)
m
(gcd n (mod m n))))
(gcd 18 45)
(display (gcd 18 45))
"""
def test_gcd():
got = run(gcd_src)
assert got == 9
def test_gcd(capsys):
run(gcd_src)
captured = capsys.readouterr()
assert captured.out == '9\n'
quicksort_src = """
@@ -216,7 +213,7 @@ closure_src = """
(define inc (make-adder 1))
(inc 99)
"""
def test_newton():
def test_closure():
got = run(closure_src)
assert got == 100
@@ -228,13 +225,15 @@ closure_with_change_src = """
n)
)
(define counter (make-counter))
(counter)
(counter)
(counter)
(display (counter))
(display (counter))
(display (counter))
"""
def test_closure_with_change():
got = run(closure_with_change_src)
assert got == 3
def test_closure_with_change(capsys):
run(closure_with_change_src)
captured = capsys.readouterr()
assert captured.out == '1\n2\n3\n'
# tag::RUN_AVERAGER[]
@@ -256,4 +255,4 @@ closure_averager_src = """
def test_closure_averager():
got = run(closure_averager_src)
assert got == 12.0
# end::RUN_AVERAGER[]
# end::RUN_AVERAGER[]