Wednesday, June 26, 2013

Answers of Concepts of Programming Languages Chapter 9

Review Questions
1. The general characteristics of subprograms :

  • Each subprogram has a single entry point
  • the calling program unit is suspended during the execution of the called subprogram, which implies that there is only one subprogram in execution at any given time
  • control always return to the caller when the subprogram execution terminates
2. if the subprogram having been called, it has begun execution but has not yet completed the execution
3. The header gives the definition of the program
4. One characteristic of Python function is the function def statements that are executable
5.
6.
7. Parameter profile of a subprogram contains the number, order and types of its formal parameters. The protocol of a subprogram is its parameter plus, if it is a function, its return type.
8. Formal parameters are parameters in the subprogram header. Actual parameters are a list of parameters to be bound to be formal parameters of the subprogram
9. The advantage of formal parameter is that they can appear in any order in the actual parameter list. The disadvantage is that the user of the subprogram must know the names of formal parameters.
10. Functions return values and procedures do not.
11.
12. The advantage of stack-dynamic local variables are the flexibility brought by them. The disadvantages are 
  • there is cost of time required to allocate, initialize and deallocate such variables for each call to the subprogram
  • accesses to stack-dynamic local variable must be indirect
  • when all local variables are stack dynamic, subprograms cannot be history sensitive
13. The advantage of static local variables is that they are slightly more efficient. The disadvantage is their inability to support recursion
14.
15. Three semantic models :
  • in mode
  • out mode
  • inout mode

Problem Set
3. The template functions of C++ are a kind of poor cousin to a subprogram in which the types of the formal parameters are dynamically bound to the types of the actual parameters in a call.
5. a. Same as the original
    b. value = 6, list = {4,1,2,8,10}
    c. Same as b
7. a. Same as the original
    b. {6,10}
    c. {6,10}
15. Ada compilers are able to determine the defined size of the dimension of all arrays that are used as parameters at the time of subprograms are compiled.

No comments:

Post a Comment