# Chapter 16 Assignment from Mr. Tri Djoko Wahjono. Ir., M.S

REVIEW QUESTION

1. What are three primary uses of symbolic logic in formal logic?

-To express propositions

-To express the relationships between propositions, and

-To describe how new propositions can be inferred from other propositions that are assumed to be true.

2.   What are the two parts of a compound term?

a functor and an ordered list of parameters

5.   What are antecedents? Consequents?

Antecedents are the right side of clausal form propositions, whereas Consequents are the left side of clausal form propositions, because it is the consequence of the truth of the antecedent.

6. Give general (not rigorous) definitions of resolution and unification

Resolution: inference rule that allows inferred propositions to be computed from given propositions, thus providing a method with potential application to automatic theorem proving.

Unification: Process of determining useful values for variables.

7.   What are the forms of Horn clauses?

Horn clauses can be in only two forms: They have either a single atomic proposition on the left side or an empty left side. The left side of a clausal form proposition is sometimes called the head, and Horn clauses with left sides are called headed Horn clauses.

10. What are the three forms of Prolog term?

Constant, variable, and structure.

PROBLEM SET

1. ”All predicate calculus propositions can be algorithmically converted to clausal form”. Is this

statement true or false?

This statement is true. Based on Nilsson (1971) proof.

7. In what way are the arithmetic processing capabilities of LISP and Prolog different?

LISP uses prefix operator in arithmetic processing, unlike Prolog.

10.  Using the internet for reference, find some of the applications of expert systems.

(source : Wikipedia)

# Chapter 15 Assignment from Mr. Tri Djoko Wahjono. Ir., M.S

REVIEW QUESTION

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

-Functional form: one that either takes one or more functions as parameters or yields a function as its result.

-Simple list: A list that does not include sublist.

-Bound variable: A bound variable is a variable which never changes in the expression after being bound to an actual parameter value at the time evaluation of the lambda expressions begin.

-Referential transparency: A state where execution of function always produces the same result when given the same parameters.

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.

6.   What is a simple list?

A list which membership of a given atom in a given list that does not include sublists.

8.   What are the three parameters to IF?

Three parameters to IF are: a predicate expression, a then expression, and an else expression.

29. What is a curried function?

Curried functions a function which a new functions can be constructed from them by partial

evaluation.

30. What does partial evaluation mean?

Partial evaluation means that the function is evaluated with actual parameters for one or more

of the leftmost formal parameters.

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.

PROBLEM SET

2.  Give the general form of function declaration in ML.

Function declarations in ML appear in the general form

fun function_name( formal parameters ) = expression;

8. How is the functional operator pipeline ( |> ) used in F#?

The pipeline operator is a binary operator that sends the value of its left operand, which is an expression, to the last parameter of the function call, which is the right operand. It is used to chain together function calls while flowing the data being processed to each call.

10. What does the following Scheme function do?

(define (x lis)

(cond

((null? lis) 0 )

((not(list? (car lis)))

(cond

((eq? (car lis) #f) (x (cdr lis)))

(else (+1 (x (cdr lis))))))

(else (+ (x (car lis)) (x (cdr lis))))

X returns the number of non-#f atoms in the given list

# Chapter 14 Assignment from Mr. Tri Djoko Wahjono. Ir., M.S

REVIEW QUESTION

3.   What are the advantages of having support for exception handling built-in to language?

• First, without exception handling, the code required to detect error conditions can considerably clutter a program.

• Another advantage of language support for exception handling results from exception propagation. Exception propagation allows an exception raised in one program unit to be handled in some other unit in its dynamic or static ancestry.

• A language that supports exception handling encourages its users to consider all of the events that could occur during program execution and how they can be handled. This approach is far better than not considering such possibilities and simply hoping nothing will go wrong.

4. Give an example of hardware-detectable execution.

Division by 0

6. What is exception propagation in Ada?

Exception propagation allows an exception raised in one program unit to be handled in some

other unit in its dynamic or static ancestry. This allows a single exception handler to be used

for any number of different program units. This reuse can result in significant savings in

development cost, program size, and program complexity

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

An exception handler in Ada can occur in either a  subprogram body, a package body, a task, or a block

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

There are four exceptions that are defined in the default package, Standard:

Constraint_aError

Program_Error

Storage_Error

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.

13. Describe three problems with Ada’s exception handling.

The propagation model, which allows exceptions to be propagated to an outer scope in which the exception is not visible, inadequacy of exception handling for tasks, and exception handling was not extended to deal with new constructs in Ada 95.

16.  Which standard libraries define and throw the exception overflow_error in C++?

The exception overflow_error is thrown by math library functions.

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;

PROBLEM SET

1. What is the 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 errors simply cause the program to be terminated and could not be transfer to operating system.

4.   What are the different approaches to handle checked exception in Java?

In Java there are basically two types of exceptions: Checked exceptions and unchecked exceptions.

Checked exceptions must be explicitly caught or propagated as described in Basic try-catch-finally Exception Handling. Unchecked exceptions do not have this requirement. They don’t have to be caught or declared thrown.

Checked exceptions in Java extend the java.lang.Exception class. Unchecked exceptions extend the java.lang.RuntimeException.

6. 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 disadvantages 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.

# Chapter 13 Assignment from Mr. Tri Djoko Wahjono. Ir., M.S

REVIEW QUESTION

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

instruction level, statement level, unit level

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

Physical concurrency is several program units from the same program that literally execute simultaneously.

Logical concurrency is 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?

Scheduler manages the sharing of processors among the tasks.

16. What is a task descriptor?

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

17. In the context of language support for concurrency, what is a guard?

Linguistic device that allows the guarded code to be executed only when a specified condition is true.

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 the purpose of an Ada terminate clause?

A terminate clause, when selected, means that the task is finished with its job but is not yet terminated. Task termination is discussed later in this section.

34.   What does the Java sleep method do?

35. What does the Java yield method do?

Yield method surrenders the processor voluntarily as a request from the running thread.

55. What is Concurrent ML?

Concurrent ML is an extension to ML that includes a form of threads and a form of synchronous message passing to support concurrency.

PROBLEM SET

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?

• Detection

• Prevention

• Avoidance

3. Busy waiting is a method whereby a task waits for a given event by continuously checking for that event to occur. What is the main problem with this approach?

Busy-waiting or spinning is a technique in which a process repeatedly checks to see if a

condition is true, such as whether keyboard input or a lock is available. Spinning can also be

used to generate an arbitrary time delay, a technique that was necessary on systems that

lacked a method of waiting a specific length of time. Processor speeds vary greatly fromcomputer to computer, especially as some processors are designed to dynamically adjust

speed based on external factors, such as the load on the operating system. Busy waiting may

loop forever and it may cause a computer freezing.

# Chapter 12 Assignment from Mr. Tri Djoko Wahjono. Ir., M.S

Review Questions

1. Name two functional languages that support object-oriented programming.

C++ and Objective-c

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.

3. What is the advantage of inheritance ?

It can be reuse and modified

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.

10.  What is an inner class?

An inner class is  a nonstatic class that is nested directly in another class.

12. From where are Smalltalk objects allocated?

Smalltalk objects are allocated from the heap and are referenced through reference variables,

which are implicitly dereferenced.

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

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

29. Does Objective-C support multiple inheritances?

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

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.

52. Does Ruby support multiple inheritance?

No. it does not

PROBLEM SET

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.

–          C++

◦ Forest of classes; when we create a class that doesn’t inherit from anything, we create a

new tree in forest.

◦ Private members of base class are not accessible in derived class.

◦ Provides inheritance specifier (public, protected, private).

◦ Interfaces and abstract classes are declared without using keywords.

◦ Virtual keyword are used explicitly.

◦ Default constructor of parent class is automatically called, but if we want to call

parametrized constructor of a parent class, we must use Initializer list.

◦ Support multiple inheritance.

–           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 (root of the

tree).

◦ 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

‘A’ doesn’t inherit from ‘B’ (they both have to be in the same package).

◦ Doesn’t provide inheritance specifier. Instead, extends keyword used for inheritance.

Therefore, we cannot change the protection level of members of base class in Java.

◦ Use a separate keyword interface for interfaces, and abstract keyword for abstract classes

and abstract functions.

◦ Methods are virtual by default.

◦ Default constructor of the parent class is automatically called, but if we want to call

parametrized constructor then we must use super to call the parent constructor.

◦ Doesn’t support multiple inheritance.

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.

10. Explain one advantage of inheritance.

• Inheritance offers a solution to both the modification problem posed by abstract data type

reuse and the program organization problem. If a new abstract data type can inherit the data

and functionality of some existing type, and is also allowed to modify some of those entities

and add new entities, reuse and is also allowed to modify some of those entities and add new

entities, reuse is greatly facilitated without requiring change to the reused abstract data type.

17.  What are the different options for object destruction in Java?

There is no explicit deallocation operator. A finalize method is implicitly called when the garbage collector is about to reclaim the storage occupied by the object.

# Chapter 11 Assignment from Mr. Tri Djoko Wahjono. Ir., M.S

REVIEW QUESTION

1.   What are two kinds of abstractions in programming language?

Two kinds of abstractions in programming languages are process abstraction and data abstraction.

2.   Define abstract data type.

The representation of objects of the type is hidden from the program units that use the type, so the only direct operations possible on those objects are those provided in the type’s definition.

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

–           Can it be parameterized?

–          What access controls are provided and how such controls are specified?

6. Explain how information hiding is provided in an Ada package.

There are two approaches to hiding the representation from clients in the package specification. One is to include two sections in the package specification—one in which entities are visible to clients and one that hides its contents.

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

With clause makes the names defined in external packages visible; in this case Ada. Text_IO, which provides functions for input of text.

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.

13. From where are C++ objects allocated?

C++ objects are allocated from heap

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

Deallocating heap space the object used.

20.  What is the use of limited private types?

Limited private types are useful when the usual predefined operations of assignment and comparison are not meaningful or useful.

21 What are initializers in Objective-C?

Intializers in Objective-C are constructors.

28. Where are Java classes allocated?

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

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

a “friend” of a given class is allowed access to public, private, or protected data in that class. Normally, function that is defined outside of a class cannot access such information.

Class that can access the private and protected members of the class in which it is declared as a friend. On declaration of friend class all member function of the friend class become friends of the class in which the friend class was declared

PROBLEM SET

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

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

11. Why is the destructor of C# rarely used ?

Because C# has its own garbage collection method , just like Java

12.  How are classes in Ruby made dynamic?

Classes in Ruby are dynamic in the sense that members can be added at any time. This is done by simply including additional class definitions that specify the new members.

# Chapter 10 Assignment from Mr. Tri Djoko Wahjono. Ir., M.Sc.

REVIEW QUESTION

2. Which of the caller or callee saves execution status information?

Saving the execution status of the caller could be done by either.

When the linker is called for a main program, its first task is to find the files that contain the translated subprograms referenced in that program and load them into memory. Then, the linker must set the target addresses of all calls to those subprograms in the main program to the entry addresses of those subprograms.

6. What is the difference between an activation record and an activation record instance?

An activation record stores all the information about subprogram calls, activation records stores :

Static link – to the static parent (where the subprogram is declared).

Dynamic link – to the caller of this subprogram.

Parameters

Local variables.

14. What are the two potential problems with the static-chain method?

A nonlocal reference is slow if the number of scopes between the reference and the declaration of the referenced variable is large.

Time-critical code is difficult, because the costs of nonlocal references are not equal, and can change with code upgrades and fixes.

PROBLEM SET

7. It is 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).

The target of every goto in a program could be represented 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.

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?