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

Basics of python-introduction, Basics of python-introduction Python is...

Basics of python-introduction Python is designed for easy interaction between a user and the system. It goes with  an inter­ active function  known as  a shell or listener.  T

Primitives, Primitives, Composition, Abstraction, and Patterns   We ...

Primitives, Composition, Abstraction, and Patterns   We will  start  by thinking about  how  the  PCAP  framework applies to computer programs, in general. We may do that by

Problem, an array A[0..n-1] of nr red elements, nw white elements and nb bl...

an array A[0..n-1] of nr red elements, nw white elements and nb blue elements in random order such that 0 = nr,nw,nb = n and nr + nw + nb = n, and arranging them such that all reds

Cps translator for python, Your task is to construct a translator from the ...

Your task is to construct a translator from the subset of Python in Project 3 intocontinuation-passing style (CPS). Of course, the expected way of accomplishing this is to trans

File handling , A program to count how many files are on the file system wh...

A program to count how many files are on the file system which displays summary information regarding the total number of bytes used by all files and a breakdown of the number of b

Python implementation of a solver for the desert crossing, Assume you have ...

Assume you have a truck which has to travel across a desert from the base camp at position 0 (left) to the target camp at position 4 (right). The intermediate positions 1,2, and 3

Question, Data array A has data series from 1,000,000 to 1 with step size 1...

Data array A has data series from 1,000,000 to 1 with step size 1, which is in perfect decreasing order. Data array B has data series from 1 to 1,000,000, which is in random order.

Program in c to generate random input - python script, For this assignment,...

For this assignment, you are to: 1.    Modify the output format of your Python script from Assignment 1 to match the input format of your C program from Assignment 2. 2.    W

Programming, We sell pdf''s from our site and pdfs can be ordered from the ...

We sell pdf''s from our site and pdfs can be ordered from the site by selecting a book, putting it in a shopping cart, then signing in with a password or as a guest, and then check

Algorithms, how to calculate area of a square in square metres

how to calculate area of a square in square metres

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