Lecture 11 Notes

G s1 v 1 so

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ¢ Example: ¡ ¥ ¥ ' # ¢  ¦  ¥   ¥ ¦¥ '  ¦ ¥ ¥ ¦¥ %  ¦ ¥ ¦¥  '   ¥ ¦¥ ¡ ¡ ¦¦¦¦¦¦ ¥¥§¥¥¥¦   which is a representation of the environment ¦%¦ ¦'¦ ¦ ( 6) ( 8) ( 7) ¤ ¡   ¦   %¢  % ¥ ¦   ¢  % ¢ ¥  %¢ ¥  ¢  constructs a scheme value There are lots of other ways to build representations of the same environment. 5 Constructors and Observers Can divide the functions in any interface into constructors that build elements of the data type, and observers that extract information from values of the data type.  ¨¦ 6 ' are the constructors, and  ¥ ¦¥  ¦  ¥    % and ¥ ¦¥ ¥ ¦¥  ' # Here only observer. is the  ¦ 2.3.2 Data Structure Representation We can obtain a representation of environments by observing that every environment can be built by starting with the empty environment and applying n times, for some n 0, e.g.,  ¦  ¥    % ¦ ¡¢¡£¡ ¦¥¦ ¥¦¥ ¦   #  ' ¢  ¦ ¥¥ ¥  %¢ ¡¡ ¢¢¡  ¦ ¥    %¢ ¥ ¦¥ s1 v 1 So every environment can be built by an expression in the following grammar: Symbol Scheme-value Env-exp 7 ¦  ¦ ¥    ¥ ¥ %¢ ¦ ¦¥ ¦   #   ¥ ' ¢ ¡ ¡ Env-exp :: :: ¥ ¦¥ sn vn 8 The procedure looks at the data structure representing an environment, determines what kind of environment it represents, and does the right thing. If it represents the empty environment, then an error is reported. If it represents an environment built by , then it checks to see if the symbol it is looking for is the same as the one bound in the environment. If it is, then the saved value is returned. Otherwise, the symbol is looked up in the saved environment. ¥ ¦¥ ¥ ¦¥   ¦ ¥    % ¥ ¦¥ ¦¦¦¦ ¥ ¥¥¥§¦ ¦¥   ¦¦¦ ¥¥§¦ # © ' © !¢ ¥  )¥  #  ¦  ¦  ' ¥ ¥ ¡  ¤ ¥ ©  ¥ ¦¥ ¦ ¦¥¦¥¦ ¥  ¥ ¦¥ ¥¦ ¦¥ ¦¥¦ ¦¥ ¥ ¦ ¥ ¥ ¦ ¥¦ ¦  # © # ©  ¤ ¥ ' '  ¡ ¦¦  ¢ ¥ ¦¥  ¡   ¢  ¡  #' ¢ ¦ ¥    ¦ %...
View Full Document

This document was uploaded on 03/17/2014 for the course CSG 111 at Northeastern.

Ask a homework question - tutors are online