schemelispracketplai

cons to empty list of type not working


I'm working through the Programming Languages: Application and Interpretation book chapter 6 http://cs.brown.edu/courses/cs173/2012/book/From_Substitution_to_Environments.html

I've applied a fix as described in the book but the cons is not adding the type to the empty list refered to in the source. I think it's a pass-by-value/pass-by-ref thing, any clues on how to set the mt-env when it's not being passed in as a parameter?

#lang plai-typed

;; Binding types
(define-type Binding
  [bind (name : symbol) (val : number)])

;; some helper functions:
(define-type-alias Env (listof Binding))
(define mt-env empty)
(define extend-env cons)

;; testing function
(define (addBinding [b : Binding] [env : Env])
  (extend-env b env)
  )

(addBinding (bind 'x 5) mt-env) ;; returns (list (bind x 5))
(display mt-env) ;; returns empty list

Below is a link to the complete code for context if required, the interp function's appC case is the specific location of my problem area, thanks. https://github.com/MickDuprez/plai/blob/master/Chapter%206/chapter-6.rkt


Solution

  • After re-reading the last part of this chapter a few times I don't think there is a simple solution to this problem. The 'change' only makes the revised interpreter behave the same as the previous 'substitution' interpreter but highlights the problem of scope with a special test case.

    This is eluded to in the next part '6.4 Scope' where the author writes:

    "The broken environment interpreter above implements what is known as dynamic scope."

    I'm sure this will be addressed in future chapters, thanks for looking anyway.