KBP Chapter 16

Assignment KBP Chapter 16:

  1. Review Question = 6
  2. Problem Set = 2

Review Questions : 

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

5. What are the antecedents? Consequent?

7. What are the forms of Horn clauses?

8. What is the basis concept of declarative semantics?

10. What are the three forms of a Prolog term?

11. What is an uninstantiated variable?

Problem Set Questions :

1. ”All predicate calculus propositions can be algorithmically converted to clausal form”. Is this statement true or false? Explain

2. Describe how a logic programming language is different from a general programming language

Review Questions Answers :

2. A compound term is composed of two parts, a functor and an ordered list of parameter

5. The right side of a clausal form proposition is called the antecendent. The left side is called the consequent because it is the consequence of the truth antecendent

7. Horn clauses can be in only two forms: they have either a single atomic proposition on the left side or an empty left side.

8. The basic concept of this semantics is that there is a simple way to determine the meaning of each statement, and it does not depend on how the statement might be used to solve a problem

10. A prolog term is a constant, a variable, or a structure

11. A variable that has not been assigned a value is called uninstantiated

Problem Set Answers :

1. The statement is true. this was proven by Nilsson (1971) by using a simple conversion algorithm

2. Logical programming language uses a form of symbolic logic, the syntax of logic programming logic is remarkably different from that of the imperative and functional languages.

 

 

KBP Chapter 15

Assignment KBP Chapter 15:

  1. Review Question = 12
  2. Problem Set = 2

Review Questions : 

2. What does a lambda expression specify?

3. What data types were parts of the original LISP?

6. What is a simple list?

7. What does the abbrevation REPL stand for?

8. What are the three parameters to IF?

11. What are the two forms of DEFINE?

22. What happens during the reader phase of a Commin Lisp language proccesor?

23. What are two ways that ML is fundamentally different from Scheme?

30. What does partial evaluation means?

31. Define reader macros

33. Explain the process of currying

39. What does F# let do?

Problem Set Questions :

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

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

Review Questions Answers :

2. A lambda expression specifies the parameters and the parameters and the mapping of a function.

3. Atoms and lists

6. The elements of simple lists are restricted to atoms

7. Read evaluation print loop

8. a predicate expression, a then expression, and an else expression

11. Define is used to bind a name to the value of an expression, the other use is to bind a lambda expressions to a name

22. There is a special kind of macro, named reader macros or read macros, that are expanded during reading phase

23. ML is strongly typed, ML uses a syntax that is more closely related to that of an imperative language than that of LISP

30. Partial evaluation means that the function is evaluated with actual parameters for one or more of the leftmost formal parameters

31. A reader macrro expands a specific character into a string of LISP code

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

39. let statement define a function that are named.

Problem Set Answers :

2. General form : fun function_name( formal parameters ) = expression;

8. (|> ) the F# functional operator is used : let inline (| >) x f = f x;;

KBP Chapter 14

Assignment KBP Chapter 14:

  1. Review Question = 10
  2. Problem Set = 4

Review Questions : 

2. When is an exception thrown or raised?

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

4. Give an example of hardware-detectable exceptions

6. What is exception handling propagation in Ada?

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

30. In which version were assertions added to Java?

31. What is the use of the assert statement?

32. What is event-driven programming?

33. What is the purpose of a Java JFrame?

36. Which package in java contains all the event related classes

Problem Set Questions :

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

6. In languages without exception-handling facilities, it is common to have most subprograms include an “error” parameter, which can be set to some value 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?

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

9. Write a comparative analysis of the throw clause and throws clause of Java

Review Questions Answers :

2. An exception is raised when its associated event occurs

3. Less clutter to detect errors, allowing a single number of handling to handle a number of events

4. Division by zero

6. Exception propagation is when an exception is raised in a package body and the package body has no handler for the exception, the exceptions then propagated to the declaration section of the unit containing the package

14. Try clause

30. Version 1.4

31. Assert statement is used for defensive programming

32. In Event driven programming, parts of the program are executed at completely unpredictable times, often triggered by user interactions with the executing program

33. JFrame class defines the data and methods that are needed to make a GUI / Frame

36. java.awt.event package

Problem Set Answers :

4. Exceptions :

  • Checked : are the exceptions that are checked at compile time. If some code within a method throws a checked exception, then the method must either handle the exception or it must specify the exception using throws clause.
  • Unchecked : are the exceptions that are not checked at compile time. It is up the programmers to specify or catch the exceptions

6. The error status code needs to be checked after each call to a subprogram. The error handling code also needs to be located everywhere a check takes place.

7. If there is a new error that aries after procceding to code our program, the exception handling function must also be updated, and separately compiled. We also have to send additional parameters.

9. Throw statement is used to retrieve the name of the class with the actual parameter, while the throws clause of Java specifies that exception class or any of its descendant exception classes can be thrown but no handled by the method

KBP Chapter 13

  • My name : Andreas Terrius
  • My NIM : 1601251146
  • My Class : 02PCT

Assignment KBP Chapter 13:

  1. Review Question = 15
  2. Problem Set = 2

Review Questions : 

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

8. What is the work of a scheduler?

9. Give some examples of languages which can be used for synchronization

10. When a task in a blocked state?

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

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

20. Describe the actions of the wait and release operations for semaphores

34. What does the Java sleep method do?

35. What does the Java yield method do?

36. What does the Java join method do?

37. What does the Java interrupt method do?

48. What kind of methods can run in a C# threads?

49. Can C# threads be actor threads, server threads, or either?

55. What is Concurrent ML?

56. What is the use of spawn primitive of CML?

Problem Set Questions :

2. What are the different ways to handle deadlock?

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?

Review Questions Answers :

7. Several program units from the same program executes simultaneously, this is called physical concurrency, while logical concurrency the actual execution of program is taking place in interlaved fashion on a single processor

8. A scheduler manages the sharing of processors among the tasks.

9. Ada, Java, C#, F#, Python

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

18. a ready task is ready to run but is not currently running, either it has not been given processor time by the scheduler, or it had run previously but was blocked

19. Competition and cooperation synchronization

20. The wait semaphore subprogram is used to test the counter of a given semaphore variable. The release semaphore subprogram is used by a task to allow some other task to have one of whatever the counter of the specified semaphore variable counts

34. Sleep method specify the number of milliseconds the thread want to be blocked and block the thread for that amount of milliseconds

35. Join method is used to force a method to delay its execution until the run method of another thread has completed its execution

36. The join method puts the thread that calls it in the blocked state, which can be ended only by the completion of the thread on which join was called.

37. The interrupt method is one way to communicate to a thread that it should stop

48. Any C# method can run in its own thread

49. C# support both actor and server threads.

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

56. Creating a thread in CML

Problem Set Answers :

2. Deadlock handling :

  • Ignoring deadlock
  • Detection : Process Terimnation and Resource preemption
  • Prevention : preventing one of the four Coffman conitions from occuring
  • Avoidance

3. The main problem would be the CPU resources that area allocated to the waiting for the task, if it were to be suspended, the CPU can then be used for other purposes

KBP Chapter 12

  • My name : Andreas Terrius
  • My NIM : 1601251146
  • My Class : 02PCT

Assignment KBP Chapter 12:

  1. Review Question = 13
  2. Problem Set = 7

Review Questions : 

1. Name two functional languages that support OOP

5.  What is an overriding method?

7. What is a dynamic dispatch?

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

9. Describe briefly the eight design issues used in this chapter for object oriented languages

12. From where are Smalltalk object allocated?

13. Explain how Smalltalk messages are bound to methods. When does this take place?

14. What type checking is done in Smalltalk? When does it take place?

15. What kind of inheritance, single or multiple, does Smalltalk support?

17. In essence, all Smalltalk variables are of a single type. What is that type?

13. How are C++ heap- allocated onjects deallocated?

24. What is the limitation of using the concept of friend in C++?

Problem Set Questions :

3. Compare the inheritance of C++ and Java

9. Given an example of inheritance in C++, where a subclass overrides the superclass methods.

10. Explain one advantage of inheritance

14. Explain type checking in Java.

16. State why Java is said to be more pure object-oriented than C++.

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

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

Review Questions Answers :

1. C++ , Java

5. An overriding method is to provide an operation in the subclass that is similar to one in the parent class, but is customized for object of the subclass

7. A dynamic dispatch is a kind of polymorphism provided bu the dynamic bindong of messages to method definitions.

8. In some cases the design of an inheritance hierarchy results in one or more classes that are so high in the hierarchy that instantiation of them would not make sense. The method inside this class will be called an abstract method, and a abstract class contains abstract methods at least one

9. Issues

  • Object exclusitivity
  • Subclasses = Subtypes ?
  • Single and multiple inheritance
  • Allocation and deallocation
  • Dynamic and static binding
  • Nested classes
  • Initialization of objects

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

13. When Dynamic binding takes place

14. Type checking in Smalltalk is dynamic, it takes palce when the message is sent

15. Small talk supports single inheritance, it does not allow multiple inheritance

16. The integrated use of windows, mouse pointing devices, and pop-up and pull down menus, all of which first appeared in small talk and the concept of OOP itself

17. Smalltalk code is generic in the sense that the types of the variables are irrelevant, as long as they are consistent.

19. Explicit deallocation can be done using the syntax delete, this is required for heap dynamic objects, because c++ doesn’t include implicit storage reclamation

24. The concept of friend trespasses the concept of OOP itself and therefore better left unused

 

Problem Set Answers :

3. Whereas C++ classes can be defined to have no parent, that is not possible in Java. All Java classes must be subclasses of the root class, Object, or some class that is a descendant of Object

9. class object {
public :
int func(){
std::cout << “x”;
}
};
class object1 : public object{
int func(){
std::cout << “y”;
}
}

10. Inheritance makes our code shorter, without inheritance every class that needs a little bit of adding from the other class will have to be copy pasted and added manually, while by inheriting we will save space (improve readability)

14. Type checking in java is basically a check whether a variable is assigned to the right value (integer with numbers, or so on), Java is one of the most heavily type checked programming language. (Dynamic type checking)

16. Almost all of java function is inside classes, while c++ still contain element from c, where without class, the programmer can still code a program.

17.  Java have garbage collector, although it still have some issues, the other alternatives would be to use the finalize method

20. While Smalltalk’s dynamic type binding provides somewhat more programming flexibility than the hybrid C++ language, it is far less efficient in the execution

KBP Chapter 11

  • My name : Andreas Terrius
  • My NIM : 1601251146
  • My Class : 02PCT

Assignment KBP Chapter 11:

  1. Review Question = 12
  2. Problem Set = 5

Review Questions : 

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

2. Define ADT

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

5. What are the language design issues for ADT?

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

7. To what is the private part of an Ada package specification visible?

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

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

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

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

13. From where are C++ object allocated?

14. In what different places can the definition of a C++ member function appear?

Problem Set Questions :

3. Write an analysis of the similarities of and differences between the access specifier of Java and C++

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

9. What happens if the constructors are absent in Java and C++?

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

15. Give one capability that Java 5.0 provides which C# 2005 does not.

Review Questions Answers :

1. process abstraction and data abstraction

2. ADT is a data type that is hidden from the program units, and the declaration of the type and the protocols, are contained in a single syntactic unit

3. Information hiding, improved readability, and easier to manage

5. Form of the container for the interface to the type, whether ADT can be parameterized,  type of access controls, whether the specification of the type is separate from its implementation

6. In Ada, the designer of an Ada package can choose to make the type entirely visible to clients or provide only the interface information.

7. The private clause is visible to the compiler but not to the client program units.

8. Limited private type is a more restricted form of private types

10. The with clause makes the names defined in external packages visible

11. The use clause eliminates the need for explicit qualification of the references to the entities from the named packages.

12. C++ classes are types, Ada packages are more generalized encapsulations that can define any number of types. A c++ program unit that declares an instance of a class can access any of the public entities in that class, but only through an instance of the class instead of Ada package, in which a program unit that gains visibility can access public entities by their names

13. In the function where an object is created

14. In the class or only in its header

Problem Set Answers :

3. C++ and Java use classes, however in Java, reliability gets prioritized over flexibility, Java and C++ classes are very similar in the term of using protected, public, and private. Each access specifier is the same whether in C++ or Java, in C++ private can only be accessed inside the class, protected is private but can be inherited to a child class, and public is accessible from outside the class. Java however need to specify everything in when we declare a variable, while in C+ we only need to write protected or private only once. Method must be defined inside of a class in Java, and all objects are allocated form the heap and accessed through reference variables.

4. The nonpointer concept in Java basically means that pointer is no longer included in Java. Pointer is a powerful but dangerous tool to use, A dangling pointer can have an impact to the overall program reliability, hence why java decided not to include pointers. The advantages is that java program is basically more reliable, and not prone to error without the existence of pointers.

9. We cannot assign values that we want on the creation time of the object, instead we have to make a separate function to assign values, and this can take time.

11. Because C# uses garbage collection for most of its heap objects.

15. One capability that Java 5.0 provides that C# 2005 does not is wildcard classes

KBP Chapter 10

  • My name : Andreas Terrius
  • My NIM : 1601251146
  • My Class : 02PCT

Assignment KBP Chapter 10:

  1. Review Question = 5
  2. Problem Set = 3

Review Questions : 

1. What is the definition used in this chapter for “simple subprograms”?

4. What the task of a linker?

10. Define static chain, static_depth, nesting_depth, and chain_offset

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

17 Describe the shallow-access method of implementing dynamic scoping

Problem Set Questions :

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 previous activation?

8. Pascal allows gotos with nonlocal targets. How could such statements be handled if static chains were used for nonlocal variable access?

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?

Review Questions Answers :

1. Subprogram cannot be nested and all local variables are static.

4. The linker task is to link the files that contains 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 all calls to those subprograms.

10. A static chain is a chain of static links that connect certain activation, record instances in the stack. static_depth is an integer associated with a static scope that indicates how deeply it is nested in the outermost scope. nesting_depth or chain_offset is a measure of how big is the difference between the static_depth of the subprogram contains the reference to x and the static depth of the subprogram contains the declaration for x

16. In deep access, the dynamic chain links together all subprogram activation record instance in the reverse of the order in which they were activated. Therefore the dynamic chain is exactly what is needed to reference nonlocal variable in a dynamic scoped language.

17. Shallow access is identical to deep access, however in shallow access, variables declared in subprograms are not stored in the activation records of those subprograms.

Problem Set Answers :

6. By using static, static basically declares the variable as a history sensitive (means if you redeclare it you will still have your last value inside it)

8. Finding the correct activation record instance of a nonlocal variable using static links is relatively straightforward. When a reference is made to nonlocal variable, the activation record instance containing the variable can be found by searching the static chain until a static ancestor activation record instance is found that contains the variable.

11. A static chain is a chain of static links that connect certain activation record instances in the stack. During the execution of a subprogram P, the static link of its activation record instance points to an activation record instance of P’s static parent program unit. That instance’s static link points in turn to P’s static grandparent program unit’s activation record instance, if there is one. So, the static chain connects all the static ancestors of an executing subprogram, in order of static parent first. This chain can obviously be used to implement the accesses to nonlocal variables in static-scoped languages.