NIM: 1801382963
Kali ini saya akan menjawab Assignment #9 dari Chapter 9 Programming Language Concepts R Sebesta
Review Questions
6. What is
a Ruby array formal parameter?
*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. What is
a parameter profile? What is a subprogram protocol?
*Parameter
profile is the number, order, and types of its formal parameters.
Subprogram
protocol is its parameter profile plus, if it is a function, its return type.
In languages in which subprograms have types, those types are defined by the
subprogram’s protocol.
8. What are
formal parameters? What are actual parameters?
*Formal
parameters are the parameters in the subprogram header.
Actual
parameters are a list of parameters to be bound to the formal parameters of the
subprogram which must be included with the name of the subprogram by the
subprogram call statements.
9. What are
the advantages and disadvantages of keyword parameters?
*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. What
are the differences between a function and a procedure?
*A function
returns value but procedures do not. Function are structurally resemble
procedures but are semantically modeled on mathematical parameter.
Problem Set
6. Present
one argument against providing both static and dynamic local variables in
subprograms.
*In
subprograms local variables can be static or dynamic;
If local variable treated statically:
This allows
for compile-time allocation/ deallocation and ensures proper type checking but
does not allow for recursion.
And if local variables treated dynamically:
This allows
for recursion at the cost of run-time allocation/ deallocation and
initialization because these are stored on a stack, referencing is indirect
based on stack position and possibly time-consuming.
7. 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 : 1,3
b. Passed
by reference : 2,6
c. Passed
by value-result : 2,6
8. Argue
against the C design of providing only function subprograms.
*If a
language provides only functions, then either programmers must live with the
restriction of returning only a single result from any subprogram, or functions
must allow side effects, which is generally considered bad. Since having
subprograms that can only modify a single value is too restrictive, C’s choice
is not good.
9. From a
textbook on Fortran, learn the syntax and semantics of statement functions.
Justify their existence in Fortran.
* The Fortran
1966 standard provided a reference syntax and semantics, but vendors continued
to provide incompatible extensions. These standards have improved portability.
10. 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.
* One of the
nice features of C++ is that you can give special meanings to operators, when
they are used with user-defined classes. This is called operator overloading.
You can implement C++ operator overloads by providing special member-functions
on your classes that follow a particular naming convention. For example, to
overload the + operator for your class, you would provide a member-function
named operator+ on your class.
Meanwhile for Ada, since much of the power of
the language comes from its extensibility, and since proper use of that
extensibility requires that we make as little distinction as possible between
predefined and user-defined types, it is natural that Ada also permits new operations
to be defined, by declaring new overloadings of the operator symbols.
No comments:
Post a Comment