Loading ...
Sorry, an error occurred while loading the content.

About clousre problem needing help

Expand Messages
  • peterzhuang2005
    when we build a clousre,we have kept the entire environment in the closure;but of course all we need are the binding for the free variables.modify the
    Message 1 of 2 , Oct 24, 2005
    • 0 Attachment
      when we build a clousre,we have kept the entire environment in the
      closure;but of course all we need are the binding for the free
      variables.modify the interpreter to use the following definition of
      closure:
      (define closure
      (lambda (proc args)
      (cases procval proc
      (closure (ids body env)
      (let ((freevars (set-diff (free-vars body) ids)))
      (let ((saved-env
      (extend-env
      freevars
      (map
      (lambda (v)
      (apply-env env v))
      freevars)
      (empty-env))))
      (lambda (args)
      (eval-expression body
      (extend-env ids args saved-env)))))))))

      i don't know how to write the free-vars function? can u tell me and
      explain ?
      thanks very much!!
    • peterzhuang2005
      when we build a clousre,we have kept the entire environment in the closure;but of course all we need are the binding for the free variables.modify the
      Message 2 of 2 , Oct 24, 2005
      • 0 Attachment
        when we build a clousre,we have kept the entire environment in the
        closure;but of course all we need are the binding for the free
        variables.modify the interpreter to use the following definition of
        closure:
        (define closure
        (lambda (proc args)
        (cases procval proc
        (closure (ids body env)
        (let ((freevars (set-diff (free-vars body) ids)))
        (let ((saved-env
        (extend-env
        freevars
        (map
        (lambda (v)
        (apply-env env v))
        freevars)
        (empty-env))))
        (lambda (args)
        (eval-expression body
        (extend-env ids args saved-env)))))))))

        i don't know how to write the free-vars function? can u tell me and
        explain ?
        thanks very much!!
      Your message has been successfully submitted and would be delivered to recipients shortly.