Procedure calls, Python Programming

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  a speci?c case of invoking a function, so we will explain with the example

 

>>> square(a + 3)

 

computed in environment E1. Here are the steps:

 

1.  The expression that determines the procedure () is computed. In this case, we compute

square in E1 and get Procedure1.

 

2.  The expressions that  determine the arguments (, ..., )  are computed. In this case, we compute a + 3 in E1 and get 5.

 

3.  A new environment (in this case E2) is prepared, which:

-  binds  the formal  parameters of the function (in this case x) to the values  of its arguments(in this case, 5); and

-  has as its base the environment in which  the procedure was de?ned we ?nd  a pointer .

 

1843_Procedure calls.png

 

The dotted line between E1 and  E2 is used to show that  E1 is the parent environmentof E2.

 

4.  The statements of the  procedure body  are computed in the  new  environment until  either  a return statement or the end of the list of statements is got. If a result expression is calculated, the expression after the return is computed and its value is returned as the value of the function call expression. Otherwise, the function has no return value,  and  the expression has the unique Python value  None.

 

In our  example, the  only  statement in the  body  is a return statement.  So, we  compute the expression x * x in E2, obtaining a value  of 25.  That  value  is returned as the value  of the entire  procedure-call expression square(a + 3).

 

This basic mechanism can generate behavior of arbitrary hardness, when grouped with  recursion or other control  structures.

 

 

 

 

Posted Date: 8/11/2012 2:04:23 AM | Location : United States







Related Discussions:- Procedure calls, Assignment Help, Ask Question on Procedure calls, Get Answer, Expert's Help, Procedure calls Discussions

Write discussion on Procedure calls
Your posts are moderated
Related Questions
Write a Python program to accomplish the following. Use modular design. Include at least 3 functions: one that returns zero values, one that returns one value, and one that retu

Python  Style Software  engineering courses  often  provide very  rigid  guidelines on the style of programming, generally the appropriate value of indentation, or what  to us

Suppose the cover price of a book is $24.95, but bookstores get a 40% discount. Shipping costs $3 for the first copy and 75 cents for each additional copy. What is the tota

Depending on your  previous programming background, we use different sides  through the available readings:   If you have never programmed before: you should start with a

Modules As you start to write larger programs, you will want  to save the function de?nitions in multiple ?les, collected together according to what  they  do.  So, for exampl

There are three seating categories at a stadium. For a softball game, Class A seats cost $15, Class B seats cost $12, and Class C seats cost $9. Write a program that asks how many

Expressions and assignment We can think of most computer programs as performing some sort of transformation on data.  Our code may get as input the exam scores of everyone in

I have python game project which is due by next Tuesday. Do you think that I can get it on time if I order today?

#que 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 cre

from urllib2 import urlopen # Open http://placekitten.com/ for reading on line 4! response = kittens.read() body = response[559:1000] # Add your ''print'' statement here!