Procedure calls, Python Programming

Assignment Help:

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.

 

 

 

 


Related Discussions:- Procedure calls

Indentation and line breaks, Every programming language has to have  some m...

Every programming language has to have  some method for indicating grouping of operations. Here is how you execute an if-then-else structure in Java:   if (s == 1){ s = s

Help, When investing money, an important concept to know is compound intere...

When investing money, an important concept to know is compound interest. The equation FV = PV (1+rate)periods . This relates the following four quantities. The present value (

Otway rees protocol implementation, I need server, client and trusted side ...

I need server, client and trusted side communicating and charging a service with that protocol (or needham shroeder)

List comprehensions, List Comprehensions   Python has a very nice b...

List Comprehensions   Python has a very nice built-in  facility for doing  many  iterative methods, known as list comprehensions. The basic template is       [

Example of Procedures as First-class objects, Procedures in Firrst-class ob...

Procedures in Firrst-class objects In Python, unlike  many  other  languages, methods are behave in much  the same way as num­ bers:  they  can be stored as values  of variabl

Variable, from urllib2 import urlopen # Open http://placekitten.com/ for...

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!

Python Program Help, Write a Python program to accomplish the following. U...

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

Work with functions, inputWithinRange (prompt, lowValue, highValue) This fu...

inputWithinRange (prompt, lowValue, highValue) This function will ask for a number using the prompt parameter. The function will only return a value that is within the inclusive ra

Character stuffing.., write code for python characters stuffing program sou...

write code for python characters stuffing program source code

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd