Lecturer: Tri Djoko Wahjono, Ir, M.Sc.

Name: Adhy Wiranata Prasetyo

NIM: 1601215733

Class: 02PBT


2.   What does a lambda expression specify?
The predicate function is often given as a lambda expression, which in ML is defined exactly like a function, except with the fn reserved word, instead of fun, and of course the lambda expression is nameless.
3.   What data types were parts of the original LISP?
Atoms and lists.

5. Explain why QUOTE is needed for a parameter that is a data list!

To avoid evaluating a parameter, it is first given as a parameter to the primitive function QUOTE, which simply returns it without change.

6.   What is a simple list?
A list which membership of a given atom in a given list that does not include sub lists.
7.   What does the abbreviation REPL stand for?
11. What are the two forms of DEFINE?
DEFINE takes two lists as parameters. The first parameter is the prototype of a function call, with the function name followed by the formal parameters, together in a list. The second list contains an expression to which the name is to be bound.
18. What is tail recursion? Why is it important to define functions that use recursion to specify repetition to be tail recursive?
A function is tail recursive if its recursive call is the last operation in the function. This means that the return value of the recursive call is the return value of the non-recursive call to the function. It is important to specify repetition to be tail recursive because it is more efficient(increase the efficiency).
The simplest form of DEFINE is one used to bind a name to the value of an expression. This form is(DEFINE symbol expression)
The general form of such a DEFINE is
(DEFINE (function_name parameters)

13. Why are CAR and CDR so named?

The names of the CAR and CDR functions are peculiar at best. The origin of these names lies in the first implementation of LISP, which was on an IBM 704 computer. The 704’s memory words had two fields, named decrement and address, that were used in various operand addressing strategies. Each of these fields could store a machine memory address. The 704 also included two machine instructions, also named CAR (contents of the address part of a register) and CDR (contents of the decrement part of a register), that extracted the associated fields. It was natural to use the two fields to store the two pointers of a list node so that a memory word could neatly store a node. Using these conventions, the CAR and CDR instructions of the 704 provided efficient list selectors. The names carried over into the primitives of all dialects of LISP.

18. What is tail recursion? Why is it important to define functions that use recursion to specify repetition to be tail recursive?

A function is tail recursive if its recursive call is the last operation in the function. This means that the return value of the recursive call is the return value of the nonrecursive call to the function. It is important to specify repetition to be tail recursive because it is more efficient(increase the efficiency).

19. Why were imperative features added to most dialects of LISP?
LISP began as a pure functional language but soon acquired some important imperative features to increased its execution efficiency.
27. What is the use of the fn reserved word in ML?
The predicate function is often given as a lambda expression, which in ML is defined exactly like a function, except with the fn reserved word, instead of fun, and of course the lambda expression is nameless.
29. What is a curried function?
Curried function let new functions can be constructed from them by partial evaluation.

32. What is the use of the evaluation environment table?

A table called the evaluation environment stores the names of all implicitly and explicitly declared identifiers in a program, along with their types. This is like a run-time symbol table.

33. Explain the process of currying!

The process of currying replaces a function with more than one parameter with a function with one parameter that returns a function that takes the other parameters of the initial function.


4.   Refer to a book on Haskell programming and discuss the features of Haskell.
Haskell features lazy evaluation, pattern matching, list comprehension, type classes, and type polymorphism.
7.   What features make F# unique when compared to other languages?
F# has a full-featured IDE, an extensive library of utilities that supports imperative, object-oriented, and functional programming, and has interoperability with a collection of nonfunctional languages. F# includes a variety of data types. Among these are tuples, like those of Python and the functional languages ML and Haskell, lists, discriminated unions, an expansion of ML’s unions, and records, like those of ML, which are like tuples except the components are named. F# has both mutable and immutable arrays.

9. What does  the following Scheme function do?

(define ( y s lis)
(( null? lis) ' () )
((equal? s (car lis)) lis)
(else (y s (cdr lis)))

y returns the given list with leading elements removed up to but not including the first occurrence of the first given parameter.



Lecturer: Tri Djoko Wahjono, Ir, M.Sc.

Name: Adhy Wiranata Prasetyo

NIM: 1601215733

Class: 02PBT


1.   Define functional form, simple list, bound variable, and referential transparency.

  • A higher-order function, or functional form, is one that either takes one or more functions as parameters or yields a function as its result, or both.
  • A simple list is the problem of membership of a given atom in a given list that does not include sublists.
  • A bound variable is a variable that never changes in the expression after being bound to an actual parameter value at the time evaluation of the lambda expression begins.
  • A referential transparency is the execution of a function always produces the same result when given the same parameters
2.   When is an exception thrown or raised?
An exception is raised when its associated event occurs.

6 . What is exception propagation in Ada?

Exception propagation in Ada: A propagation that allows an exception raised in one program unit to be handled in some other unit in its dynamic or static ancestry.

9. What is the scope of exception handlers in Ada?

The scope of exception handlers in Ada: The exception that can be included in blocks or in the bodies of subprograms, packages, or tasks.

10. What are the four exceptions defined in the Standard package of Ada?

Four exceptions that are defined in the Standard package of Ada:





11. are they any predefined exceptions in Ada?

Yes, they are.

12. What is the use of Suppress pragma in Ada?

The suppress pragma is used to disable certain run-time checks that are parts of the built-in exceptions in Ada.

14. What is the name of all C++ exception handlers?

Try clause

30. In which version were assertions added to Java?

Assertions were added to Java in version 1.4.

31. What is the use of the assert statement?

The assert statement is used for defensive programming. A program may be written with many assert statements, which ensure that the program’s computation is on track to produce correct results.

33. What is the purpose of a Java JFrame?
The JFrame class defines the data and methods that are needed for frames. So, a class that uses a frame can be a subclass of JFrame. A JFrame has several layers, called panes.
34. What are the different forms of assert statement?
There are two possible forms of the assert statement:
  • assert condition;
  • assert condition : expression;


1. What mechanism did early programming languages provide to detect or attempt to deal with errors?

Early programming languages were designed and implemented in such a way that the user program could neither detect nor attempt to deal with such errors. In these languages, the occurrence of such an error simply causes the program to be terminated and control to be transferred to the operating system.

2. Describe the approach for the detection of subscript range errors used in C and Java!

In C subscript ranges are not checked. Java compilers usually generate code to check the correctness of every subscript expression. If any exception generates, then an unchecked exception is thrown.

6.In languages without exception-handling facilities, it is common to have most subprograms include an “error” parameter, which can be set to some values representing “OK” or some other value representing “error in procedure”? What advantage does a linguistic exception-handling facility like that of Ada have over this method?

There are several advantages of a linguistic mechanism for handling exceptions, such as that found in Ada, over simply using a flag error parameter in all subprograms. One advantage is that the code to test the flag after every call is eliminated. Such testing makes programs longer and harder to read. Another advantage is that exceptions can be propagated farther than one level of control in a uniform and implicit way. Finally, there is the advantage that all programs use a uniform method for dealing with unusual circumstances, leading to enhanced readability.

7. In languages without exception-handling facilities, we could send an error-handling procedure as parameter to each procedure that can detect errors than must be handled. What disadvantage are there to this method?

There are several disadvantages of sending error handling subprograms to other subprograms. One is that it may be necessary to send several error handlers to some subprograms, greatly complicating both the writing and execution of calls. Another is that there is no method of propagating exceptions, meaning that they must all be handled locally. This complicates exception handling, because it requires more attention to handling in more places.

14. Summarize the arguments in favor of the termination and resumption models of continuation!

The resumption model is useful when the exception is only an unusual condition, rather than an error. The termination model is useful when the exception is an error and it is highly unlikely that the error can be corrected so that execution could continue in some useful way.


Lecturer: Tri Djoko Wahjono, Ir, M.Sc.

Name: Adhy Wiranata Prasetyo

NIM: 1601215733

Class: 02PBT


1.   What are the three possible levels of concurrency in programs?

  • Instruction level (executing two or more machine instructions simultaneously)
  • Statement level (executing two or more high-level language statements simultaneously)
  • Unit level (executing two or more subprogram units simultaneously)
4.   What level of program concurrency is best supported by SIMD computers?
Statement-level concurrency
5.   What level of program concurrency is best supported by MIMD computers?
 Unit-level concurrency is best supported by MIMD computers.

7. What is the difference between physical and logical concurrency?

  • Physical concurrency: Several program units from the same program that literally execute simultaneously
  • Logical concurrency:  Multiple processors providing actual concurrency, when in fact the actual execution of programs is taking place in interleaved fashion on a single processor.

8. What is the work of a scheduler?

The work of a scheduler is a scheduler that manages the sharing of processors among the tasks

12. What is a heavyweight task? What is a lightweight task?

Heavyweight Task: The task that executes in its own address space.

Lightweight Task: The tasks that run in the same address space.

16. What is a task descriptor?

Task descriptor: A data structure that stores all of the relevant information about the execution state of a task.

18. What is the purpose of a task-ready queue?

The purpose of a task-ready queue is to be storage of tasks that are ready to run.

19. What are the two primary design issues for language support for concurrency?

preventing concurrent processes from interfering with each other

21. What is a binary semaphore? What is a counting semaphore?

A binary semaphore is  a semaphore that requires only a binary-valued counter. A counting semaphore is a synchronization object that can have an arbitrarily large number of states.

30. What is purpose of an Ada terminate clause?

The purpose of an Ada terminate clause is mark the task that its finished with its job but is not terminated yet.

34. What does the Java sleep method do?

The Java sleep method blocks the the thread.

35. what does the Java yield method do?
The yield method, which takes no parameters, is a request from the running thread to surrender the  voluntarily. The thread is put immediately in the task-ready queue, making it ready to run. The scheduler then chooses the highest-priority thread from the task-ready queue. If there are no other ready threads with priority higher than the one that just yielded the processor, it may also be the next thread to get the processor.
36. What does the Java join method do?
Java forces a method to delay its execution until the run method of another thread has completed its execution.
37. What does the Java interrupt method do?
Interrupt becomes one way to communicate to a thread that it should stop.

42. What kind of Java object is a monitor?

In Java, a monitor can be implemented in a class designed as an abstract data type, with the shared data being the type. Accesses to objects of the class are controlled by adding the synchronized modifier to the access methods.
55. What is Concurrent ML?
ML is an extension to ML that includes a form of threads and a form of synchronous message passing to support concurrency.
56. What is the use of the spawn primitive of CML?

The use of Spawn primitive of CML is to create a thread.

57. What is the use of subprograms BeginInvoke and EndInvoke in F#?

The use of subprograms BeginInvoke and Endinvoke in F# is to call threads asynchronously.

58. What is the use of the DISTRIBUTE and ALIGN specification of HPC?

The use of DISTRIBUTE and ALIGN specification of HPC is to provide information to the compiler on machines that do not share memory, that each processor has its own memory.

60. What is the type of an F# heap-allocated mutatable variable?
A mutable heap-allocated variable is of type ref
1.   Explain clearly why a race condition can create problems for a system.

Because two or more tasks are racing to use the shared resource and the behavior of the program depends on which task arrives first (and wins the race). The importance of competition synchronization should now be clear.
2.   What are the different ways to handle deadlock?
  • Ignoring deadlock
  • Detection
  • Prevention
  • Avoidance
4.   In the producer-consumer example of Section 13.3, suppose that we incorrectly replaced the release(access) in the consumer process with wait(access). What woud be the result of this error on execution of the system?
Deadlock would occur if the release(access) were replaced by a wait(access) in the consumer process, because instead of relinquishing access control, the consumer would wait for control that it already had.


Lecturer: Tri Djoko Wahjono, Ir, M.Sc.

Name: Adhy Wiranata Prasetyo

NIM: 1601215733

Class: 02PBT

2. What are the problems associated with programming using abstract data types?

  • In nearly all cases, the features and capabilities of the existing type are not quite right for the new use.
  • The type definitions are all independent and are at the same level.

4. What is message protocol?

Message protocol is the entire collection of methods of an object.

5. What is an overriding method?

Overriding method is method that overrides the inherited method.

7.What is dynamic dispatch?

Dynamic dispatch is the third characteristic (after abstract data types and inheritance) of
object-oriented programming language which is a kind of polymorhphism provided by the dynamic
binding of messages to method definitions.

8.What is an abstract method? What is an abstract class?

An abstract method is an implemented method which all of descendant class should have and it is
included in Building. An abstract class is a class that includes at least one abstract method.

11. What is the message protocol of an object?

The message protocol of an objects are all the methods.

12. From where are Smalltalk objects allocated?

Smalltalk objects are allocated from the heap and are referenced through reference variables,
which are implicitly dereferenced.

18. From where can C++ objects be allocated?

The objects of C++ can be static, stack dynamic, or heap dynamic. Explicit deallocation using
the delete operator is required for heap-dynamic objects, because C++ does not include implicit
storage reclamation.

19. How are C++ heap-allocated objects deallocated?

C++ heap-allocated objects are deallocated using destructor.

29. Does Objective-C support multiple inheritance?

No Objective-C doesn’t support it. (It supports only single inheritance).

31. What is the root class in Objective-C?

The predefined root class named NS Object

33. What is the purpose of an Objective-C category?

The purpose of an Objective-C category is to add certain functionalities to different classes and also to provide some of the benefits of multiple inheritance, without the naming collisions that could occur if modules did not require module names on their functions.

38. What is boxing?

Boxing is primitive values in Java 5.0+ which is implicitly coerced when they are put in object
context. This coercion converts the primitive value to an object of the wrapper class of the
primitive value’s type.

39. How are Java objects deallocated?

By implicitly calling a finalizemethod when the garbage collector is about to reclaim the
storage occupied by the object.


1 . What important part of support for inheritance is missing in Java?

Java does not support the private and protected derivations of C++. One can surmise that the Java designers believed that subclasses should be subtypes, which they are not when private and protected derivations are supported. Thus, they did not include them.

2. In what ways can “compatible “ be defined for the relationship between an overridden method
and the overriding method?

Every overriding method must have the same number of parameters as the overridden method and the types of the parameters and the return type must be compatible with those of the parent class.

3. Compare the inheritance of C++ and Java!


  • All classes inherit from the Object class directly or indirectly
  • If we create a class that doesn’t inherit from any class, then it automatically inherits from

Object Class
– Members of the grandparent class are not directly accessible
– Protected members of a class “A” are accessible in other class “B” of same package, even if B
doesn’t inherit from A
– Java uses extends keyword for inheritance
– We don’t have to remember those rules of inheritance which are combination of base class
access specifier and inheritance specifier
– Methods are virtual by default
– Uses a separate keyword interface for interfaces and abstract keyword for abstract classes and
abstract functions


  • Private members of base class are not accessible in derived class
  • Have the forest of classes. When we create a class that doesn’t inherit from anything, we create a new tree in forest
  • Support the multiple inheritance
  • Default constructor of parent class is automatically called, but if we want to call parametrized the constructor of a parent class, we must use Initalizer list
  • Use virtual keyword

5. Compare abstract class and interface in Java!
– Abstract class is a class while interface is a interface, means by extending abstract class
you can not extend another class because Java does not support multiple inheritance but you can
implement multiple inheritance in Java.

– You can not create non abstract method in interface, every method in interface is by default
abstract, but you can create non abstract method in abstract class. Even a class which doesn’t
contain any abstract method can be abstract by using abstract keyword.

– The abstract class are slightly faster than interface because interface involves a search
before calling any overridden method in Java

– The interface are better suited for Type declaration and abstract class is more suited for
code reuse and evolution perspective

– When you add a new method in existing interface it breaks all its implementation and you need
to provide an implementation in all clients which is not good. By using abstract class you can
provide default implementation in super class

7. What is one programming situation where multiple inheritance has a significant disadvantage
over interfaces?

A situation when there are two classes derived from a common parent and those two derived class
has one child.

9. Give an example of inheritance in C++, where a subclass overrides the superclass methods!
class bird{

void fly(){
cout << “Fly, Fly away!” << endl;
class ostrich:public class bird{
void fly()
cout << “Fly, Fly away! But I can’t!” << endl;
10. Explain one advantage of inheritance.

One of the key benefits of inheritance is to minimize the amount of duplicate code in an application by sharing common code amongst several subclasses. Where equivalent code exists in two related classes, the hierarchy can usually be refactored to move the common code up to a mutual super class. This also tends to result in a better organization of code and smaller, simpler compilation units.

20. Compare the way Smalltalk provides dynamic binding with that of C++

In C++, the programmer can specify whether static binding or dynamic binding is to be used. Because static binding is faster, this is an advantage for those situations where dynamic binding is not necessary. Furthermore, even the dynamic binding in C++ is fast when compared with that of Smalltalk. Binding a virtual member function call in C++ to a function definition has a fixed cost, regardless of how distant in the inheritance hierarchy the definition appears. Calls to virtual functions require only five more memory references than statically bound calls (Stroustrup, 1988). In Smalltalk, however, messages are always dynamically bound to methods, and the farther away in the inheritance hierarchy the correct method is, the longer it takes. The disadvantage of allowing the user to decide which bindings are static and which are dynamic is that the original design must include these decisions, which may have to be changed later.

25. Study and explain private and public modifiers in C++. How do those modifiers differ in C#?

C++ includes both classes and structs, which are nearly identical constructs. The only difference is that the default access modifier for class is private, whereas for structs it is public. C# also has structs, but they are very different from those of C++. In C#, structs are, in a sense, lightweight classes. They can have constructors, properties, methods, and data fields and can implement interfaces  but do not support inheritance.


Lecturer: Tri Djoko Wahjono, Ir, M.Sc.

Name: Adhy Wiranata Prasetyo

NIM: 1601215733

Class: 02PBT


2.Define abstract data type

  • the representation of objects of the type is hidden from the program units that use the type
  • the declarations of the type and the protocols of the operations on objects of the type

3.What are the advantages of the two parts of the definition of abstract data type

  • the program will increase reliability, reduce the range of code and number variables
  • it provides a method of organizing a program into logical units that can be compiled separately.

5. What are the language design issues for abstract data types

  • the form of the container for the interface to the type
  • whether abstract data type can be parameterized
  • what access controls are provided and how such controls are specified
  • whether the specification of the type is physically separate from its implementation

8.What is the difference between private and limited private types in Ada?

Private types in Ada, it has built-in operations for assignment and comparisons for equality and inequality. Limited private types in Ada, are described in the private section of a package specification, as are non pointer private types. Limited private types are declared to be limited private in the visible part of the package specification.

9.What is in an ada package specification? What about a body package?

A package specification and its associated body package share the same name. The reserved word body in a package header identifies it as being a body package. A package specification and its body package may be compiled separately.

10. What is the use of the Ada with clause?

With clause makes the names defined in external packages visible.

11. What is the use of the Ada use clause?

Use clause eliminates the need for explicit qualification of the references to entities from the named package.

12. What is the fundamental difference between a C++ class and an Ada package?

C++ is have a few encapsulations.  Ada packages are more generalize encapsulations that can define any number of types.

15. What is the purpose of a C++ destructor?

The purpose of a C++ desctructor is as a debugging aid, in which case they simply display or print the values of some or all of the object’s data members before those members are deallocated.

21. What are initializers in Objective-C?

The initializers in Objective-C are constructors.

22. What is the use of @private and @public directives?

The use is to specify the access levels of the instance variables in a class definition.

27. Where are all java methods defined?

All java methods are defined completely in a class. A method body must appear with its corresponding method header

28. Where are java classes allocated?

Java classes allocated from the heap and accessed through reference variables.

30. What is a friend function? What is a friend class?

Friends Function: A “friend” of a given class is allowed access to public, private, or protected
data in that class.
Friend Class: Class that can access the private and protected members of the class in which it
is declared as a friend.

43. What is a C++ namespace, what is its purpose?

In general, a namespace is a container for a set of identifiers and allows the disambiguation of
homonym identifiers residing in different namespaces. The purpose is to help programs manage the
problem of global namespace.

45. Describe a .NET assembly

.NET assembly is a .NET application that appears to be a single dynamic link library (.dll) or
an executable (.exe). An assembly defines a module, which can be separately developed and
includes several different components.


4. What are the advantages of the nonpointer concept in Java

  • There is no memory leak such as dangling pointers or unnamed variables.
  • Memory access via pointer arithmetic – this is fundamentally unsafe. Java has a robust security model and disallows pointer arithmetic for this reason.
  • Array access via pointer offsets – Java does this via indexed array access so you don’t need pointers. A big advantage of Java’s indexed array access is that it detects and disallows out of bounds array access, which can be a major source of bugs.
  • References to objects – Java has this, it just doesn’t call them pointers. Any normal object reference works as one of these.

8. What are the drawbacks of user-defined generic classes in Java 5.0?

Some drawbacks of user-defined generic classes in Java 5.0 are: for one thing, they cannot store primitives. Second, the elements cannot be indexed. Elements must be added to user-defined generic collections with the add method.

9. What happens if the constructor is absent in Java and C++?

It will be made automatically by the built-up in.

10. Which two conditions make data type “abstract” ?

  • The representation, or definition, of the type and the operations are contained in a single syntactic unit
  • The representation of objects of the type is hidden from the program units that use the type

19. Compare Java’s packages with Ruby’s modules.

In Ruby, the require statement is used to import a package or a module. For example, the extensions package/module is imported as follows.

require 'extensions'

External files may be included in a Ruby application by using load or require. For example, to include the external file catalog.rb, add the following require statement.

require "catalog.rb"

The difference between load and require is that load includes the specified Ruby file every time the method is executed and require includes the Ruby file only once.

In Java, the import statement is used to load a package. For example, a Java package java.sql is loaded as follows.

import java.sql.*;


Lecturer: Tri Djoko Wahjono

Name: Adhy Wiranata Prasetyo

NIM: 1601215733

Class: 02PBT


4.What is the task of a linker?

The task of a linker is to find the files that contain the translated subprograms referenced in that and load them into memory

5.What are the two reasons why implementing subprograms with stack-dynamic local variables is
more difficult than implementing simple subprograms?

the compiler must generate code to cause the implicit allocation and deal-location of local
variables recursion adds the possibility of multiple simultaneous activations of a subprogram which means
that there can be more than one instance at a given time.

10. Define static chain, static_depth, nesting depth and chain_offset

Static chain is a chain of static links that connect certain activation record instances in the stack. Static depth is an interger associated with a static scope that indicated how deeply it is nested in the outermost scope. Nesting depth is the length of the static chain needed to reach the correct activation record instance for a nonlocal reference to a variable X

Chain_offset is the length of static depth of the subprogram containing the reference to X and
declaration for X.

15. Explain the two methods of implementing blocks

  • deep access
  • shallow access

16. Describe the deep-access method of implementing dynamic scoping

The dynamic chain links together all subprogram activation record instances in the reverse of the order in which they were activated. The dynamic chain is exactly what is needed to reference nonlocal variables in a dynamic-scoped language.

17. Describe the shallow-access method of implementing dynamic scoping

An alternative implementation method, not an alternative semantics. In the shallow-access method, variables declared in subprograms are not stored in the activation records of those subprograms.

19. Compare the efficiency of the deep access method to that of the shallow access method, in term of both call and nonlocal access?

The deep access methods provides fast subprogram linkage, but references to nonlocal, especially
references to distant nonlocals (in term of the call chain), are costly. The shallow access
methods provide much faster references to nonlocals, especially distant nonlocals, but are more
costly in term of subprogram linkage.


7. It stated in this chapter that when nonlocal variables are accessed in a dynamic-scoped language using the dynamic chain, variable names must be stored in the activation records with the values. If this were actually done, every nonlocal access would require a sequence of costly string comparisons on names. Design an alternative to these string comparisons that would be faster.

One very simple alternative is to assign integer values to all variable names used in the program. Then the integer values could be used in the activation records, and the comparisons would be between integer values, which are much faster than string comparisons.

8. Pascal allows gotos with nonlocal targets. How could such statements be handled if static chains were used for nonlocal variable access? Hint: Consider the way the correct activation record instance of the static parent of a newly enacted procedure is found (see Section 10.4.2).

Following the hint stated with the question, the target of every goto in a program could be as an address and a nesting_depth, where the nesting_depth is the difference between the nesting level of the procedure that contains the goto and that of the procedure containing the target. Then, when a goto is executed, the static chain is followed by the number of links indicated in the nesting_depth of the goto target. The stack top pointer is reset to the top of the activation record at the end of the chain.

9. The static-chain method could be expanded slightly by using two static links in each activation record instance where the second points to the static grandparent activation record instance. How would this approach affect the time required for subprogram linkage and nonlocal references?

Including two static links would reduce the access time to nonlocals that are defined in scopes two steps away to be equal to that for nonlocals that are one step away. Overall, because most nonlocal references are relatively close, this could significantly increase the execution efficiency of many programs.

11. If a compiler uses the static chain approach to implementing blocks, which of the entries in the activation records for subprograms are needed in the activation records for blocks?

There are two options for implementing blocks as parameterless subprograms: One way is to use the same activation record as a subprogram that has no parameters. This is the most simple way, because accesses to block variables will be exactly like accesses to local variables. Of course, the space for the static and dynamic links and the return address will be wasted. The alternative is to leave out the static and dynamic links and the return address, which saves space but makes accesses to block variables different from subprogram locals.


Lecturer: Tri Djoko Wahjono

Name: Adhy Wiranata Prasetyo

NIM: 1601215733

Class: 02PBT


1. What are the three general characteristics of subprograms?

Each subprogram has a single entry point, excluding co-routine. The calling program 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 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.

4. What are formal parameters? What are actual parameters?

The parameters in the subprogram header are called formal parameters. Subprogram call statements must include the name of the subprogram and alist of parameters to be bound to the formal parameters of the subprogram. These parameters are called actual parameters.

5.What are the advantages and disadvantages of keyword parameters?

The advantage of keyword parameter is that they can appear in any order in the actual parameter

The disadvantage to keyword parameters is that the user of the subprogram must know the names of
formal parameters.

6.What are the design issues for subprograms?

  • What parameter-passing method or methods are used?
  • Are the types of the actual parameters checked against the types of the formal parameters?
  • Are local variable statically or dynamically allocated?
  • Can subprogram definitions appear in other subprogram definitions?
  • If subprograms can be passed as parameters and subprograms can be nested, what is the
  • referencing environment of a passed subprogram?
  • Can a subprogram be overloaded?
  • Can subprograms be generic?

7. What are the advantages and disadvantages of dynamic local variables?


  • They provide flexibility to the subprogram
  • The storage of local variables in an active subprogram can be shared with the local variables in
  • all inactive subprograms.
  • They efficiently used when computer has small memory (Faster Access).


  • Cost of the time required to allocate
  • Access to dynamic local variable must be indirect
  • The stack dynamic local variables, subprograms cannot be history sensitive

10. In what ways can aliases occur with pass-by-reference parameters?

Aliases can be occurring because pass-by-reference makes access paths available to the called subprograms.

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?
  • 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?

  • 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.


  • there is the cost of time required to allocate, initialize and deallocate such variables for each 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.

18. What causes a C++ template function to be instantiated?

C++ template functions are instantiated implicitly either when the function is named in a call
or when its address is taken with the & processor.

19. In what fundamental way do the generic parameters to a Java 5.0 generic method differ from
those of C++ methods?

Java does not use objects exclusively, java have no enumeration or record type. Whereas C++
Classes can be defined to have no parent, that is not possible in Java. All Java Classes must be
subclass of the root class.

25. What is ad hoc binding?
Ad hoc binding is the environment of the call statement that passed the subprogram as an actual

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.


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.

6 . Compare and contrast PHP’s parameter passing with that of C#!

PHP’s parameter passing is similar to that of C#, except that either the actual parameter or the
formal parameter can specify pass-by-reference. Passby- reference is specified by preceding one
or both of the parameters with an ampersand.

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 handles 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. In Ada, unconstrained array types can
be formal parameters. An unconstrained array type is one in which the index ranges are not given
in the array type definition.


Lecturer: Tri Djoko Wahjono

Name: Adhy Wiranata Prasetyo

NIM: 1601215733

Class: 02PBT


1. What is the definition of control structure?

A control structure is a primary concept in most high-level programming languages. In its
simplest sense, it is a block of code. More specifically, control structures are blocks of code
that dictate the flow of control. In other words, a control structure is a container for a
series of function calls, instructions and statements.A simple example of a control structure
is, if a then b else c. These statements will be included or excluded based o­n the condition of
a. This simple notion of if then comprises the bulk of even the most sophisticated software

2. What did Bohm and Jocopini prove about flowcharts?

It was proven that all algorithms that can be expressed by flowcharts can be coded in a
programming languages with only two control statements: one for choosing between two control
flow paths and one for logically controlled iterations.

3. What is the definition of block?
a block is a section of code which is grouped together. Blocks consist of one or more
declarations and statements. A programming language that permits the creation of blocks,
including blocks nested within other blocks, is called a block-structured programming language.
Ideas of block structure were developed in the 1950s during the development of the first
autocodes, and were formalized in the Algol 58 and Algol 60 reports. Algol 58 introduced the
notion of the “compound statement”, which was related solely to control flow. The subsequent
Revised Report which described the syntax and semantics of Algol 60 introduced the notion of a
block and block scope, with a block consisting of ” A sequence of declarations followed by a
sequence of statements and enclosed between begin and end…” in which “every declaration
appears in a block in this way and is valid only for that block.”

7.Under what circumstances must an F# selector have an else clause?
An F# selector have an “else” clause if the “if” expression does return a value.

9. What are the design issues for multiple-selection statement?
The following is a summary of these design issues:
-What is the form and type of the expression that controls the selection?
– How are the selectable segments specified?
– Is execution flow through the structure restricted to include just a single selectable
– How are the case values specified?
– How should unrepresented selector expression values be handled, if at all?

14. What are the design issues for all iterative control statements?
How is the iteration controlled?
Where should the control mechanism appear in the loop statement?

15. What are the design issues for counter-controlled loop statements?

What are the type and scope of the loop variable?
Should it be legal for the loop variable or loop parameters to be changed in the loop, and if
so, does the change affect loop control?
Should the loop parameters be evaluated only once, or once for every iteration?

21. What are the design issues for logically controlled loop statements?

Should the control be pretest or post-test?
Should the logically controlled loop be a special form of a counting loop or a separate

22. What is the main reason user-located loop control were invented?
It is convenient for a programmer to choose a location for loop control other than the top or
bottom of the loop body. As a result, some languages provide this capability. A syntactic
mechanism for user-located loop control can be relatively simple, so its design is not
difficult. Such loops have the structure of infinite loops but include user-located loop exits.

26. What is a user-defined iteration control?
A user-defined iteration control is the one that issues a special call to the iterator, in which
the iterator is called at the beginning of each iteration, and each time it is called, the
iterator returns an element from a particular data structure in some specific order.


1.What design issues should be considered for two-way selection statements?
The design issues for two-way selectors can be summarized as follows:
· What is the form and type of the expression that controls the selection?
· How are the then and else clauses specified?
· How should the meaning of nested selectors be specified?

4. What are the limitations of implementing a multiple selector from two-way selectors and
A multiple selector can be built from two-way selectors and gotos, but the resulting structures
are cumbersome, unreliable, and difficult to write and read.

5. What are the arguments pro and con, for Java’s approach to specify compound statements in
control statements?

• Compound statements are required in control statements when the body of the if or else clause
requires multiple statements.

• Java uses braces to form compound statements, which serve as the bodies of if and else

9. Boolean expressions are necessary in the control statements in Java, as opposed to also
allowing arithmetic expressions, as in C++. Give a conditional statement that is correct in C++
but not in Java.
if( 1 )
// in C++, 1 will be considered as true and 0 as false. Java does not allow this.

Concept of Programming Languages Chapter 7

Lecturer: Tri Djoko Wahjono

Class: 02PBT

2.What is a ternary operator?
Ternary operator is an operator that takes three arguments. The arguments and result can be of different types. Many programming languages that use C-like syntax feature a ternary operator, ?:, which defines a conditional expression. Since this operator is often the only existing ternary operator in the language, it is sometimes simply referred to as “the ternary operator”. In some languages, this operator is referred to as “the conditional operator”.
3.What is a prefix operator?
a prefix operator is one which signifies a function of one argument, which argument immediately follows an occurrence of the operator.
8.Define functional side effect
Functional side effect is a side effect of a function, occurs when the function changes either one of its parameters or a global variable.
12.Define narrowing and widening conversions
Narrowing conversion is a conversion of data that might cause a loss of precision.
Widening conversion is a conversion that converts a value to a type that can include least approximations of all values of the original type.
15.What is referential transparency?
Referential transparency is a property of programming constructs, which is enforced by some functional programming languages. In a referentially transparent program, a function/method invocation can be freely replaced with its return value without changing the program’s semantics.
18.What is short-circuit evaluation?
Short-circuit evaluation, minimal evaluation, or McCarthy evaluation denotes the semantics of some Boolean operators in some programming languages in which the second argument is only executed or evaluated if the first argument does not suffice to determine the value of the expression: when the first argument of the AND function evaluates to false, the overall value must be false; and when the first argument of the OR function evaluates to true, the overall value must be true. In some programming languages (Lisp), the usual Boolean operators are short-circuit. In others (Java, Ada), both short-circuit and standard Boolean operators are available. For some Boolean operations, like XOR, it is not possible to short-circuit, because both operands are always required to determine the result.
28.What is a cast
Cast means converting between data types, may be used explicitly or implicitly.


1. When might you want the compiler to ignore type differences in an expression?
The compiler ignore type differences in an expression would be useful when an expression compare or check the inputted type format.
In C, when a character is inputted into an integer the program will break and as far as I know C doesn’t have error handling like Java.
3.Do you think the elimination of overloaded operators in your favorite language would be beneficial? Why or why not?
No, my favourite language so far is C++. The elimination of overloaded operators would make a function manipulation is less than before.
4. Would it be a good idea to eliminate all operator precedence rules and require parentheses to show the desired precedence in expressions ? Why and why not ?
No, because the precedence rules would make the code simpler, and improves readability, since it’s easier to follow through the known precedence according to the rules than follow through many parentheses
7. Describe a situation in which the add operator in a programming language would not be commutative.
example: int num=0;
num + (++num) = 1
when reversed
(++num) + num = 2
from the above example can be shown that the add operator in a statement might not always be commutative.
15.Explain why it is difficult to eliminate functional side effects in C
Because when a function is used, except its output only depends on the input, it will has side effects. No further manipulation and no data structure can be used to avoid it, which is difficult since many C programs relies on them.


Lecturer: Tri Djoko Wahjono

1.What is a descriptor?
Descriptor is the collection of the attributes of a variable.
2.What are the advantages and disadvantages of decimal data types?
Decimal data types is able to precisely store decimal values, at least those within a restricted range, which cannot be done with floating-point.
5.Define ordinal, enumeration, dan subrange types.
ordinal type is one in which the range of possible values can be easily associated with the set of positive integers.
enumeration type is one in which all of the possible values, which are named constants, are provided.
A subrange type defines a subset of the values of a particular type. By using subrange types, you can easily detect errors occuring due to unreasonable values of a variable which shouldn’t take values outside a given boundary.
8.What are the design issues for arrays?
-Which types are legal for subscripts
-The checking of subscripting expressions in element references range.
-The time the subscript ranges bound
-The place where array allocated
-The use of ragged or rectangular multidimensioned arrays
-Initialization of an allocated storage
-Kind of slices are allowed in the array
17.Define row major order and column major order
row major order is an order which a multidimensional array in linear memory is organized such that rows are stored one after another.
column major order is an order which listing the columns in sequence to flatten arrays onto linear memory.
23.What is the primary difference between a record and a tuple?
Unlike a record, the elements in a tuple is not named.
31. Define union, free union, and discriminated union
Union is a type whose variables may store different type values at different times during program execution.
Free union is unions which used to specify union structures, so that programmers are allowed complete freedom from type checking in their use.
Discriminated union is unions with type indicator which called tag or discriminant.
35.What are the design issues for pointer types?
-The scope and lifetime of a pointer variable
-lifetime of a heap-dynamic variable
-Restriction of pointers as to the type of value to which they can point to
-The use of pointers between for dynamic storage management, indirect addressing, or both
-The support of language should be for pointer types, reference types, or both
36.What are the two common problems with pointers?
-May lead to several kinds of programming errors.
-The problems present in the pointers of subsequent languages.
44.Define type error
Type type is the application of an operator to an operand of an inappropriate type.
45.Define strongly typed
A programming language is strongly typed if type errors are always detected. This requires that the types of all operands can be determined, either at compile time or at run time.
50.What is name type equivalence?
Name type equivalence means that two variables have equivalent types if they are defined either in the same declaration or in declarations that use the same type name.
51.What is structure type equivalence?
Structure type equivalence means that two variables have equivalent types if their types have identical structures.
52.What is the primary advantage of name type equivalence?
Easy to implement, despite being more restrictive.


2.How are the negative integers stored in memory?
Negative numbers are represented in 2’s complement form, which is a sign-magnitude notation stored in memory.
7.Compare the pointer and reference type variable in C++
A pointer can be re-assigned, as for a reference cannot, and must be assigned at initialization.
A pointer has its own memory address and size, as for a reference it shares the same memory address.
8.What are the differences between the reference type variable of C++ and those of Java?
Java does not have pass by reference like in C++. The references are passed by vale.
9.C provides two derived data types both for name and structure type equivalence: struct and union. Make a study on when to use struct type variables and union type variables?
Union have a slightly more effective on size and memory to use, so if the data (2 or more) is mutually exclusive, union is better to use than struct. But if it is a separated data with different data types, it is better to use struct
6.Compare the use of Boolean data types in C++ and Java. Give emphasis on their use in conditional statements and conditional loops.
In C++, 1 goes for true and 0 goes for false, so it can be used as a condition in the conditional statements and loops as the condition.
As in Java,Boolean doesn’t accept integers as true or false value, just true and false condition instead. So for conditional statements and loops it cannot be used as the explicit condition.
21. In what way is dynamic type checking better than static type checking?
Dynamic type checking is better than static type checking because it is better to detect error at compile time that at run time, beacause the earlier correction is usually less costly. The static type checking reduced programmer flexibility.