Name : Fandy Limardi
NIM : 1601210713
Lecture : Tri Djoko Wahjono, Ir., M.Sc. (D0206)
Assignment : Concept of programming languages ---- Chapter 9 Subprograms
Review Questions
1. What are the three general characteristics of
subprograms?
·
each
subprogram has a single entry point
·
the
calling program unit is suspended during the execution of the called subprogram
·
control
always returns to the caller when the subprogram execution terminates
2. What does it mean for a subprogram to be
active?
A subprogram is said to be active
after having been called, it has begun execution but has not yet completed that
execution.
6. What is ruby array formal parameter?
ruby array formal parameter is
the single parameter which followed by the hash item which preceded by an
asterik. Ruby allows a variable number of parameters in a way similar to C#
because ruby arrays can store different types.
7. What is a parameter profile? what is a subprogram protocol?
Parameter profile is a subprogram contains
the number, order , and types of its formal
parameters. Subprogram protocol is a subprogram which its parameter profile plus, if it is a
function , its return type. In languages in which subprogram have types, those types are
defined by the subprogram's protocol.
parameters. Subprogram protocol is a subprogram which its parameter profile plus, if it is a
function , its return type. In languages in which subprogram have types, those types are
defined by the subprogram's protocol.
11. What are the design issues for subprograms?
·
are
local variables statically or dynamically allocated?
·
can
subprogram definitions appear in other subprogram definitions?
·
what
parameter-passing method or methods are used?
·
are
the types of the actual parameters checked against the types of the formal parameters?
·
if
a subprograms can be passed as parameters and subprograms can be nested, what
is the
referencing environment of a passed subprogram?
referencing environment of a passed subprogram?
·
can
subprograms be overloaded?
·
can subprograms be generic?
·
if
the language allows nested subprograms , are closures supported?
12. What are the advantages and disadvantages of
dynamic local variables?
Advantages
·
being
flexibility they provide to the subprogram
·
the
storage for local variables in an active subprogram can be shared with the
local
variables in all inactive subprograms.
variables in all inactive subprograms.
Disadvantages
·
there
is the cost of time required to allocate, initialize and deallocate such
variables for each
call to the subprogram.
call to the subprogram.
·
accesses
to stack- dynamic local variables must be indirect.
·
when
all local variables are stack dynamic, subprograms cannot be history sensitive.
24. What is an overloaded subprogram?
Overloaded subprogram is a
subprogram that has the same name as another subprogram in the same referencing
environment
25. What is ad hoc binding?
Ad hoc binding is the environment
of the call statement that passed the subprogram as an actual parameter
26. What is multicast delegate?
Multicast delegate is all of the
methods stored in a delegate instance are called in the order in which they
were placed in the instance.
Problem Set
3. Argue in support of the template functions of
C++. How is it different from the template functions in other languages?
C++
templated classes are instantiated to become typed classes at compile time. For
example, an instance of the templated Stack class, as well as an instance of the
typed class, can be created with the following declaration: Stack<int>
myIntStack; However, if an instance of the templated Stack class has already
been created for the int type, the typed class need not be created.
4. Suppose
you want to write a method that prints a heading on a new output page, along
with a page number that is 1 in the first activation and that increases by 1
with each subsequent activation. Can this be done without parameters and
without reference to nonlocal variables in Java? Can it be done in C#?
This
can be done in both Java and C#, using a static (or class) data member for
the page number.
11. Compare
the use of closures by programming languages.
Nearly all functional programming languages, most
scripting languages, and at least one primarily imperative language, C#,
support closures. These languages are static-scoped, allow nested
subprograms, and allow subprograms to be passed as parameters.
12. Research Jensen’s Device, which was a widely
known use of pass-by-name parameters, and write a short description of what it
is and how it can be used.
Implementing
a pass-by-name parameter requires a subprogram to be passed to the called
subprogram to evaluate the address or value of the formal parameter. The
referencing environment of the passed subprogram must also be passed. This
subprogram/referencing environment is a closure. Pass-by-name parameters are
both complex to implement and inefficient. They also add significant complexity
to the program, thereby lowering its readability and reliability. Because
pass-by-name is not part of any widely used language, it is not discussed
further here. However, it is used at compile time by the macros in assembly
languages and for the generic parameters of the generic subprograms in C++,
Java 5.0, and C# 2005.
15. How
is the problem of passing multidimensional arrays handled by Ada?
Ada compilers are able to determine the defined size
of the dimensions of all arrays that are used as parameters at the time
subprograms are compiled.
No comments:
Post a Comment