Lecture 5 Notes

each declares a new anonymous variable and

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: ograms that might perform an inappropriate operation. 3. Then in lecture 7, we will use the same kind of analysis to establish abstraction boundaries in programs and reject those programs that violate the abstraction boundaries. 11 4.2.1 Eliminating Variable Names Execution of the scoping algorithm may then be viewed as a journey outward from a variable reference to its matching declaration We could, therefore, get rid of variable names entirely, and replace variables with their lexical depths. For example, we could replace the Scheme expression § £ ¨¢ © §   )© !  § !§  £ ¢ §§ !¨£ by something like:  ©  )¢  © ) ¢ § )§ ¡ ¢¡ ¡ ¢¡ #©# ¨ # #  © ¢  ¦£ §¥ ¤ £ ¡ ¢ ¢¡ # © #   ! ¦ §£ § !§  )©  Each declares a new anonymous variable, and each variable reference is replaced by its lexical depth; this number uniquely identifies the declaration to which it refers. These numbers are called lexical addresses or deBruijn indices. 12 This way of recording the information is useful because the lexical address predicts just where in the environment any particular variable will be found. Consider the expression e2 § ¨¥ ¥ £ ¥ $# %© $# %© £ in our language. In the difference expression, the lexical depths of and 1, respectively. and £ £¤ ¢ ¢ ¡ ¢ ¡ e1 are 0 Now assume that the values of e1 and e2 , in the appropriate environments, are v 1 and v2 . Then the value of this expression is ¥ I# © ¢ ¡ ¡ £ e1 § ¨¥ ¥ £ ¥ I# © ¢ ¡ ©  $# %© ¥ §¥   £ £ ¢ § ¡ # £ ©  £ ¢ §¥ v1 ¥ §   ©   §§ £ ¥ ¦¨ ¤ ¢ ¦¥ ¥I© ¢    © §§ £ ¦¨ ¤ ¢ ¢ ¥ ¡ ¦¥ v2 £ ¥ ¦¥ $# %© v1 e2 §  ©  $# %© §§ ©¨ £¤ ¢ ¢ ¡ ¢ e2 ¥ so that when the difference expression is evaluated, is at depth 0 and is at depth 1, just as predicted by their lexical depths. 13 If we use a data-structure representation of environments like we did for LET, th...
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