Name : Vina Melinda
NIM : 1801380106
Untuk kali ini saya akan menjawab Assignment #11 Problem Set dan Review Questions dari Chapter 9 dari Sebesta.
Review Questions:
6. Q: What is a Ruby array formal parameter?
A: Ruby supports a complicated but highly flexible actual parameter configuration. The initial parameters are expressions, whose value objects are passed to the corresponding formal parameters. The initial parameters can be following by a list of key => value pairs, which are placed in an anonymous hash and a reference to that hash is passed to the next formal parameter. These are used as a substitute for keyword parameters, which Ruby does not support. The hash item can be followed by a single parameter preceded by an asterisk. This parameter is called the array formal parameter.
7. Q: What is a parameter profile? What is a subprogram protocol?
A: Parameter profile of a subprogram contains the number, order, and types of its formsl parameter. A protocol of subprogam is ite parameter profile plus, if it is a function, its return type。
A: Parameter profile of a subprogram contains the number, order, and types of its formsl parameter. A protocol of subprogam is ite parameter profile plus, if it is a function, its return type。
8. Q: What are formal parameters? What are actual parameters?
A: Formal parameter is the parameter in the subprogram header. They are sometimes thought of as dummy variables because they are not variable in the usual case. Actusl parameter is a subprogram call statement that must inckude the nameof the subprogram and a list of parameters to be bound to the formal parameter of the subprogram.
9. Q: What are the advantages and disadvantages of keyword parameters?
A: The advantage of keyword parameters is that they can appear in any order in the actual parameter list. The disadvantage to keyword parameters is that the user of the subprogram must know the names of formal parameters.
A: Formal parameter is the parameter in the subprogram header. They are sometimes thought of as dummy variables because they are not variable in the usual case. Actusl parameter is a subprogram call statement that must inckude the nameof the subprogram and a list of parameters to be bound to the formal parameter of the subprogram.
9. Q: What are the advantages and disadvantages of keyword parameters?
A: The advantage of keyword parameters is that they can appear in any order in the actual parameter list. The disadvantage to keyword parameters is that the user of the subprogram must know the names of formal parameters.
10. Q: What are the differences between a function and a procedure?
A: A function returns a value and a procedure just executes commands. The name function comes from math. It is used to calculate a value based on input. A procedure is a set of command which can be executed in order. In most programming languages, even functions can have a set of commands. Hence the difference is only in the returning a value part. But if you like to keep a function clean, (just look at functional languages), you need to make sure a function does not have a side effect.
A: A function returns a value and a procedure just executes commands. The name function comes from math. It is used to calculate a value based on input. A procedure is a set of command which can be executed in order. In most programming languages, even functions can have a set of commands. Hence the difference is only in the returning a value part. But if you like to keep a function clean, (just look at functional languages), you need to make sure a function does not have a side effect.
Problem Set:
6. Q: Present one argument against providing both static and dynamic local
variables in subprograms.
A: In subprograms local variables can be static or dynamic. If local variable treated statically, this allows for compile-time allocation or deallocation and ensures proper type checking but doesn't allow recursion. However, if local variables treated dynamically, this allows for recursion at the cost of run-time allocation or deallocation and initialization because these are stored on a stack, referencing is indirect based on stack position and possibly time consuming.
variables in subprograms.
A: In subprograms local variables can be static or dynamic. If local variable treated statically, this allows for compile-time allocation or deallocation and ensures proper type checking but doesn't allow recursion. However, if local variables treated dynamically, this allows for recursion at the cost of run-time allocation or deallocation and initialization because these are stored on a stack, referencing is indirect based on stack position and possibly time consuming.
7. Q:Consider the following program written in C syntax:
void fun (int first, int second) {
first += first;
second += second;
}
void main() {
int list[2] = {1, 3};
fun(list[0], list[1]);
}
For each of the following parameter-passing methods, what are the values
of the list array after execution?
a. Passed by value
b. Passed by reference
c. Passed by value-result
A: a. 1, 3
b. 2, 6
c. 2, 6
void fun (int first, int second) {
first += first;
second += second;
}
void main() {
int list[2] = {1, 3};
fun(list[0], list[1]);
}
For each of the following parameter-passing methods, what are the values
of the list array after execution?
a. Passed by value
b. Passed by reference
c. Passed by value-result
A: a. 1, 3
b. 2, 6
c. 2, 6
8. Q: Argue against the C design of providing only function subprograms.
A: If a language only provides functions, then programmers must live with the restriction of returning only one result from any subprogram or functions must allow side effects, which is considered bad.
A: If a language only provides functions, then programmers must live with the restriction of returning only one result from any subprogram or functions must allow side effects, which is considered bad.
9. Q: From a textbook on Fortran, learn the syntax and semantics of statement
functions. Justify their existence in Fortran.
A: The Fortran 90 standard (ISO/IEC 1539: 1991) describes the syntax and semantics of a programming language. However, the standard addresses certain aspects of the Fortran processing system, but does not address others. When specifications are not covered by the standard, the interpretation is processor dependent; that is, the processor defines the interpretation, but the interpretation for any two processors need not be the same. Programs that rely on processor-dependent interpretations typically are not portable. (Jeanne C. Adams, Walter S. Brainerd, et. al., 1992)
functions. Justify their existence in Fortran.
A: The Fortran 90 standard (ISO/IEC 1539: 1991) describes the syntax and semantics of a programming language. However, the standard addresses certain aspects of the Fortran processing system, but does not address others. When specifications are not covered by the standard, the interpretation is processor dependent; that is, the processor defines the interpretation, but the interpretation for any two processors need not be the same. Programs that rely on processor-dependent interpretations typically are not portable. (Jeanne C. Adams, Walter S. Brainerd, et. al., 1992)
10. Q: Study the methods of user-defined operator overloading in C++ and Ada,
and write a report comparing the two using our criteria for evaluating
languages.
A: C was downgraded because it is essentially limited to syntactic (re)naming of predefined data types and data structures, with building-block capabilities within these limitations. Unlike Ada, neither C nor C++ allows restrictions to the range of a type. The C++ extensions to C in this category are the most significant enhancement. A class in C++ is a user-defined data type that provides data hiding, guaranteed initialization of data, implicit type conversion for user-defined types, dynamic typing, user-controlled memory management, and mechanisms for overloading operators. Ada has been downgraded slightly by the SEI for lacking a mechanism like classes that permits programming by specialization and extension. (Nelson H. Weiderman, 1991)
and write a report comparing the two using our criteria for evaluating
languages.
A: C was downgraded because it is essentially limited to syntactic (re)naming of predefined data types and data structures, with building-block capabilities within these limitations. Unlike Ada, neither C nor C++ allows restrictions to the range of a type. The C++ extensions to C in this category are the most significant enhancement. A class in C++ is a user-defined data type that provides data hiding, guaranteed initialization of data, implicit type conversion for user-defined types, dynamic typing, user-controlled memory management, and mechanisms for overloading operators. Ada has been downgraded slightly by the SEI for lacking a mechanism like classes that permits programming by specialization and extension. (Nelson H. Weiderman, 1991)