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
I need server, client and trusted side communicating and charging a service with that protocol (or needham shroeder)

draw the variation of pressure with volume of a real gas at temperatures lower than its critical temperature.also draw its surface of discontinuity

You should use for whenever you can, because  it creates  the structure of your  loops clear. Sometimes, however, you require to do an operation various times, but you don't want t

Non-local references in procedures There  is an important subtlety in the  way  names  are handled in the  environment created by a function call. When  a value  that  is not

Import the sample code below into the Python IDLE and enhance it, run it and debug it. Add features to make this a more realistic database tool by providing for easy data entry an

Use the function to compute and print the sum of first n prime numbers.

for simple interest and compound interest

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.

python program of motion of a particle in viscus medium

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