Beispiel #1
0
def test_lookup_from_inner_env():
    """The `extend` function returns a new environment extended with more bindings."""

    env = Environment({"foo": 42})
    env = env.extend({"bar": True})
    assert_equals(42, env.lookup("foo"))
    assert_equals(True, env.lookup("bar"))
Beispiel #2
0
def test_extend_returns_new_environment():
    """TEST 4.5: The extend method should create a new environment, leaving the old one unchanged."""

    env = Environment({"foo": 1})
    extended = env.extend({"foo": 2})

    assert_equals(1, env.lookup("foo"))
    assert_equals(2, extended.lookup("foo"))
Beispiel #3
0
def test_extend_returns_new_environment():
    """The extend method should create a new environment, leaving the old one unchanged."""

    env = Environment({"foo": 1})
    extended = env.extend({"foo": 2})

    assert_equals(1, env.lookup("foo"))
    assert_equals(2, extended.lookup("foo"))
Beispiel #4
0
def test_lookup_from_inner_env():
    """TEST 4.3: The `extend` function returns a new environment extended with more bindings.

    Tip: The Dictionary class has a convenient .update method.
    """

    env = Environment({"foo": 42})
    env = env.extend({"bar": True})
    assert_equals(42, env.lookup("foo"))
    assert_equals(True, env.lookup("bar"))
def test_make_sure_arguments_are_evaluated_in_correct_environment():
    """Test 5.19: Function arguments should be evaluated in correct environment

    Function arguments should be evaluated in the environment where the function
    is called, and not in the environment captured by the function.
    """

    env = Environment({'x': 3})
    res = evaluate(parse("(define foo (lambda (x) x))"), env)
    env = env.extend({'x': 4})
    assert_equals(evaluate(parse("(foo (+ x 1))"), env), 5)
def test_make_sure_arguments_are_evaluated_in_correct_environment():
    """Test 5.19: Function arguments should be evaluated in correct environment

    Function arguments should be evaluated in the environment where the
    function is called, and not in the environment captured by the function.
    """

    env = Environment({'x': 3})
    evaluate(parse("(define foo (lambda (x) x))"), env)
    env = env.extend({'x': 4})
    assert_equals(evaluate(parse("(foo (+ x 1))"), env), 5)