this is done in racket scheme an environment can be represented by a list of associa 5187957
This is done in racket/scheme.
An environment can be represented by a list of association lists (i.e., a list of symbol tables), where the first element in the list is the nearest scope, the second the next surrounding scope, and the last the outermost scope.
Write a recursive function, lookup-env, which returns the binding with the specified name in the nearest scope. If no such binding is found, return nil.
Example:
(
define l1
'((
ben “short”) (
cara “walking”) (
dan “bald”))) (
define l2
'((
albert “is not”) (
ski “skinny”) (
kim “cook”) (
cara “injured”))) (
define e (list l1 l2) ) (
lookup-env 'ben e)
=> (
ben “short”) (
lookup-env 'albert e)
=> ('albert “is not”) (
lookup-env 'cara e)
=> (
cara “walking”) (
lookup-env 'eggbert e)
=> ()
(define (lookup-env name env) | |
#f) |