Non-local references, Python Programming

Non-local references

So far, whenever we needed to compute a variable, there  was  a binding for that  variable in the 'local' environment (the environment in which  we were evaluating the expression). But take this code:

 

def biz(a):

return a + b

 

>>> b = 6

 

2176_Non-local references.png

 

We need to elaborate, slightly,  how it is that a variable v is computed in an environment E:

 

  • We take if there is a binding for v in E; if so, we stop and return it.

 

  • If not, we compute v in the parent environment of E. If E has no base, we create an error.

 

It is important to check that this method  will continue up an arbitrarily long chain of environ­ ments  and their parents until either a binding for v is found or there are no more environments to examine.

So, in our case, we will compute the expression a + b in environment E2. We start by calculating a and searching value 2 in E2. Then, we compute b and cannot search it in E2...but we don't panic! We take the parent pointer to E1 and  try again.  We search a binding for b in E1 and  get the value  6. So, the value  of a + b in E2 is 8.

 

Posted Date: 8/11/2012 2:43:21 AM | Location : United States







Related Discussions:- Non-local references, Assignment Help, Ask Question on Non-local references, Get Answer, Expert's Help, Non-local references Discussions

Write discussion on Non-local references
Your posts are moderated
Related Questions
how to make a python programme for van der waals equation of state with surface discontinouty

#ques Write the pseudocode (use a word processor please) and the Python 3.0 program for the following problem. A monkey is being fed some food. Read in the starting weight in lbs:o

for simple interest and compound interest

Write a program that will take price data for stocks and print it graphically to the screen. Your program should begin by asking the user for the file name. It should then create a

Procedure calls When you compute an expression of the form ( ,  ..., )   the Python interpreter treats  this as a procedure call. It will be simpler to talk about

Rewrite the area.py program (shown below, or in the Creating Functions section of the tutorial) so that it has separate functions for the perimeter and area of a square, a rectangl

what are the issues assciated with top-down analysis

I need how to write small kind of viruses...

Common Errors and Messages Here are some common Python errors  and error  messages to look  out for. Please let us give if you have any favorite additions for this list.

Imagine a "particle" located on the centre square of a two-dimensional grid of dimensions 11 by 75. The particle can only move one square at a time, either up, down, left, or right