Concept of programming language 10th edition chapter 16

assignment assigned by Mr. Tri Djoko Wahjono


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?
=> Two parts of a compound term are:  a functor, which is the function symbol that names the relation, and an ordered

list of parameters, which together represent an element of the relation.

3. What are the two modes in which a proposition can be stated?
=> Propositions can be stated in two modes: one in which the proposition is defined to be true, and one in which the

truth of the proposition is something that is to be determined. In other words, propositions can be stated to be facts or


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.

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. Headed Horn clauses are used to state relationships, such as likes( bob, trout ) likes( bob, fish ) x

fish( trout )

11. What is an uninstantiated variable?
=> An uninstantiated variable is a variable that has not been assigned a value.

13. What is a conjunction?
=> Conjunctions contain multiple terms that are separated by logical AND operations.


1.”All predicate calculus propositions can be algorithmically converted to clausal form”. Is this statement true or false?
=> This statement is true. Nilsson (1971) gives proof that this can be done, as well as a simple conversion algorithm

for doing it.

2. Describe how a logic programming language is different from a general programming language.
=> Programming that uses a form of symbolic logic as a programming language, unlike other general programming language,

is often called logic programming; languages based on symbolic logic are called logic programming languages, or declarative


10. Using the internet for reference, find some of the applications of expert systems.
=> – Expert system in healthcare: The Electronic health record (EHR) is designed to replace the traditional medical and

bring together a more versatile, expansive and robust expert system to provide greater quality care.
– Expert systems in the financial field: Loan departments are interested in expert systems for morgages because of

the growing cost of labour, which makes the handling and acceptance of relatively small loans less profitable.
– A new application for expert systems is automated computer program generation. Funded by a US Air Force grant, an

expert system-based application (hprcARCHITECT) that generates computer programs for mixed processor technology

(FPGA/GPU/Multicore) systems without a need for technical specialists has recently been commercially introduced.


Concept of programming language 10th edition chapter 15


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.

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

7. What does the abbreviation REPL stand for?
=>REPL stand for read-evaluate-print loop.

11. What are the two forms of DEFINE?
=> 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) (expression)

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

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

26. What is type inferencing, as used in ML?
=> Type inference refers to the automatic deduction of the type of an expression in a programming language. If some,

but not all, type annotations are already present it is referred to as type reconstruction.

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.

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.


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.

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.

10.What does  the following Scheme function do?

(define ( x lis)
(( null? lis) 0 )
(( not(list? (car lis)))
((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

Concept of programming language 10th edition chapter 14

assignment assigned by mr Tri Djoko Wahjono



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?
=> Exception handlers 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?
=> There are four exceptions that are defined in the default package, Standard:
– Constraint_aError
– Program_Error
– Storage_Error
– Tasking_Error
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.

32. What is event-driven programming?
=> Event-driven programming is a programming where parts of the program are executed at completely unpredictable times,

often triggered by user interactions with the executing program.

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.

Concept of programming language 10th edition chapter 13

assignment assigned by mr. Tri Djoko Wahjono

BAB 13


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

Instruction level, statement level, unit level

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

Physical concurrency is the most natural category of concurrency is that in which, assuming that more than one processor is available, several program units from the same program literally execute simultaneously.

Logical concurrency is a slight relaxation of this concept of concurrency allows the programmer and the application software to assume that there are multiple processors providing actual concurrency, when in fact the actual execution of programs is taking place in interleaved fashion on a single processor.

  1. What is a thread of control in a program?

Is the sequence of program points reached as control flows through the program.

10. What is a multithreaded program?

A program that designed to have more than one thread of control

11. What are four reasons for studying language support for concurrency?

  • The speed of execution of programs on machines with multiple
  • Even when a machine has just one processor, a program written to use concurrent execution can be faster than the same program written for sequential (nonconcurrent) execution. processors.
  • Concurrency provides a different method of conceptualizing program solutions to problems.
  • Program applications that are distributed over several machines, either locally or through the Internet.

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

heavyweight task executes in its own address space

lightweight task all run in the same address space.


15. Describe the five different states in which a task can be.

1. New: A task is in the new state when it has been created but has not yet begun its execution.

2. Ready: A ready task is ready to run but is not currently running.

3. Running: A running task is one that is currently executing

4. Blocked: A task that is blocked has been running, but that execution was interrupted by one of several different events, the most common of which is an input or output operation.

5. Dead: A dead task is no longer active in any sense.


16. What is a 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?

Guard is a 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?

Binary semaphore is a semaphore that requires only a binary-valued counter, like the one used to provide competition synchronization in the following example

counting semaphore is a synchronization object that can have an arbitrarily large number of state

23. What advantage do monitors have over semaphores?

This solution can provide competition synchronization without semaphores by transferring responsibility for synchronization to the run-time system.


24. In what three common languages can monitors be implemented?

Ada, java, C#


33. Are Java threads lightweight or heavyweight tasks?

Lightweight task


35. What does the Java yield method do?

To make the thread is put immediately in the task-ready queue. Making it ready to run.

36. What does the Java join method do?

Used to force a method to delay its execution until the run method of another thread has completed its execution.

44. What are the two methods used with Java Semaphore objects?

Acquired and release


2. What is the best action a system can take when deadlock is detected?

  • Interrupt (i.e. send a signal/exception to) all the threads holding the lock. They will have to be able to handle the resulting interrupt, though.
  • Kill all the threads/processes involved. This is a drastic action, and it saves the rest of the system at the expense of the risk that some data will probably be lost by the program.

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 from computer 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.

Concept of programming language 10th edition chapter 12

assignment assigned by mr. Tri Djoko Wahjono


  1. Describe the three characteristic features of object-oriented languages.

Encapsulation refers to mechanisms that allow each object to have its own data and methods

Polymorphism refers to the capability of having methods with the same names and parameter types exhibit different behavior depending on the receiver.

Inheritance refers to the capability of defining a new class of objects that inherits from a parent clas

  1. What is the difference between a class variable and an instance variable?

Class variable belong to class, rather than its object, so there is only one copy for the class

Instance variable is a variable defined in a class for which each object of the class has a separate copy, or instance

  1. What is multiple inheritance?

The process when class have more that one parent class

  1. What is a polymorphic variable?

A variable that can hold different types of values during the course of execution. Called “pure polymorphism” when a polymorphic variable is used as a parameter

  1. What is an overriding method?

Overridden method is the new method is said to override the inherited method

  1. What is a virtual method?

Virtual method is a function or method whose behavior can be overridden within an inheriting class by a function with the same signature

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

Abstract method is one with only a signature and no implementation body. It is often used to specify that a subclass must provide an implementation of the method

10. What is a nesting class?

The class in which the new class is nested

11. What is the message protocol of an object?

The entire collection of methods of an object

23. What are the differences between private and public derivations in C++?

Private derivation both the public and protected members of the base class are private

Public derivation both the public and protected members of a base class are also public and protected, respectively.

25. What is a pure virtual function in C++ ?

Pure virtual function meaning that it has no body and it cannot be called

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

to permit the programmer to add methods to an existing class without the need to recompile that class or even have access to its source code

34. What is the purpose of an Objective-C protocol?

For achievable either as an abstract multiply inherited base class in C++, or as an “interface”


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

in ways of its formal definition, the parameters and return types.

7. What is one programming situation where multiple inheritance has a significant disadvantage over interfaces ?When two or more parent classes are derived from one grandparent class and has one child. (diamond problem)

3. Explain the two problems with abstract data types that are ameliorated by inheritance?

Two problems of abstract data types that are ameliorated by inheritance are: (a) Reuse of abstract data types is much easier, because the modifications of existing types need not be done on the legacy code, and (b) with abstract data types, all types are independent and at the same level, disallowing any logically hierarchical type dependencies.

  1. Explain one disadvantage of inheritance.

Disadvantage of using inheritance is that the two classes (base and inherited class) get tightly coupled.
This means one cannot be used independent of each other.

12. What exactly does it mean for a subclass to have an is-a relationship with its parent class?

“Is-a” implies inheritance. The derived class has all of the public methods and properties of the parent class (plus some of its own). This is useful because other parts of the application can accept parameters of the parent class type, and since all derived classes “is-a” that type, you can pass any one of those to the method. It gives you polymorphism without having to write a separate (but virtually identical) method for every conceivable child type, or without using “object”, “void *”, etc., which throw type safety out the window.

16. What is the primary reason why all Java objects have a common ancestor?

Java is an object oriented language, which means that one of its core principles is inheritance. All classes (and hence the objects created from them) are derived from a parent. In this way, classes inherit variables, methods, and classes from their parent so that they do not have to redefine them. In Java’s case, the common parent of all classes is Object. This gives every class some basic functionality, such as the equals, toString, and wait methods. Besides uniformity, another advantage of inheritance is clear organization. Imagine if we could not guarantee the comparison of two objects with the equals method. Finally, a global parent class means that every class, no matter how specific, can be generalized into the parent’s type (Object o = new String()).

17. What is the purpose of the finalize clause in Java?

The finalize() method is called by the garbage collector just before the object is disposed of and the memory reclaimed. It was initially intended as a way for the programmer to clean up external resources used by the object, like closing a database connection or an open file.

Concept of programming language 10th edition chapter 11

assignment assigned by mr. Tri Djoko Wahjono


  1. What are the two kinds of abstractions in programming languages?

Process abstraction and data abstraction

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


Increased reliability and reduce the rage of code and number variables of which a programmer must be aware when writing or reading a part of the program.

4. What are the language design requirements for a language that supports

abstract data types?

Must provide a syntactic unit that encloses the declaration of the type and the prototype of the subprograms that implement the operations on objects of the data type.

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

Makes the names defined in external packages visible.

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

Eliminates the needs for explicit qualification of the reference to entities from the named package.

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


Ada provides an encapsulation that can be use to stimulated abstract data types, C++ provides two constructs that are very similar to each other the class and the struct, which more directly support abstract data type.

C++ classes are types; as stated previously, Ada packages are more generalized encapsulations that can define any number of types. A program unit that gains visibility to an Ada package can access any of its public entities directly by their names. A C++ program unit that declares an instance of a class can also access any of the public entities in that class, but only through an instance of the class.

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

To initialize the data member of newly created object.

27 . Where are all Java methods defined?

In class

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

Friend function to allowed access to public, private, or protected data in that class.

Friend class can access the “private” and “protected” members of the class in which it is declared as a friend

31. What is one reason Java does not have friend functions or friend classes?

Because java has less need for explicit friend declarations

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

to helps programs manage the

problem of global namespaces. One can place each library in its own namespace

and qualify the names in the program with the name of the namespace when

the names are used outside that namespace.

44. What is a Java package, and what is its purpose?

Java package is a mechanism for organizing Java classes into namespaces similar to the modules of Modula.

allowing classes to download faster as a group rather than one at a time and to organize classes belonging to the same category or providing similar functionality.

Problem set ()

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

Any task that would require arrays, structures, and pointers in C can be more easily and reliably performed by declaring objects and arrays of objects. Instead of complex pointer manipulation on array pointers, you access arrays by their arithmetic indices. The Java run-time system checks all array indexing to ensure indices are within the bounds of the array. You no longer have dangling pointers and trashing of memory because of incorrect pointers, because there are no pointers in Java.

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, so only direct operations possible on those objects are those provided in the type’s definition

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

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

15. Explain why naming encapsulations are important for developing large


  • is to provide a way to organize programs into logical units for compilation. This allows parts of programs to be recompiled after isolated changes. There is another kind of encapsulation that is necessary for constructing large programs.
  • prevalent in any object that is created in combination
  • used to hide the values or state of a structured data object inside a class, preventing unauthorized parties direct access to them.
  • Each library can create its own naming encapsulation to prevent its names from conflicting with the names defined in other libraries or in client code. Each logical part of a software system can create a naming encapsulation with the same purpose.
  • Several different collections of code can be placed in the same namespace, even though they are stored in different places.

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

In java encapsulation construct called package .Packages can contain more than one type definition, and the types in a package are partial friends of one another.

In ruby a encapsulation construct called module. Modules typically define collections of methods and constants. So, modules are convenient for encapsulating libraries of related methods and constants, whose names are in a separate namespace so there are no name conflicts with other names in a program that uses the module. Modules are unlike classes in that they cannot be instantiated or subclassed and do not define variables.

Concept of programming language 10th edition chapter 10

Chapter 10

Review Question

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

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 program and load them into memory.

6. What is the difference between an activation record and an activation record instance?
=> An activation record is the format, or layout, of the moncode part of a subprogram, whereas an activation record instance is a concrete example of an activation record, a collection of data in the form of an activation record.

8. What kind of machines often use registers to pass parameters?
=> RISC.

11. What is an EP, and what is its purpose?
=> EP is a point or first address of the activation record instance of the main program. It is required to control the execution of a subprogram.

Problem Set

6. Although local variables in Java methods are dynamically allocated at the beginning of each activation,
under what circumstances could the value of a local variable in a particular activation retain the value of
the previous activation?
=> If the variable is declared as static. Static modifier is a modifier that makes a variable history – sensitive.

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