Thursday, June 27, 2013

Answers of Concepts of Programming Languages Chapter 16

Review Questions
1. Symbolic logic can be used for the three basic needs of 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. Functor and an ordered list of parameters

3. Propositions can be started 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.

4. The general clausal form of proposition :
B1 U B2 U ... U Bn ⊂ A1 ∩ A2 ∩ ... ∩ An

5. Antecedent is the right side of a clausal form proposition. The left side is consequent

7. Horn clauses can be in only two forms : single atomic proposition on the left side or right side

8. Basic concept of declarative semantics is 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

Problem Set
2. Declarative semantics is considerably simpler than the semantics of the imperative language. Programming in a logic programming language is nonprocedural

10. One of the most widely known uses of logic programming in expert systems is the expert system construction system known as APES. The APES system includes a very flexible facility for gathering information from the user during expert system construction.

Wednesday, June 26, 2013

Answers of Concepts of Programming Languages Chapter 15

Review Questions
2. A lambda expression specifies the parameters and the mapping of a function
3. Atoms and lists
4. In a linked list structure
5. The necessity of QUOTE arises because of the fundamental nature of Scheme : data and code have the same form
6. Simpel lists are the lists which elements are restricted to atoms
7. read-evaluate-print loop
13. The origin of the name of CAR AND CDR lies in the first implementation of LISP, which was on an IBM 704 computer.
14. AB
18. Tail recursive function is a function whose recursive call is the last operation in the function. Regardless of how many recursive calls are requested, only one activation record instance is necessary, if we use the tail recursive function
20. Scheme is far smaller and semantically simpler, in part because of its exclusive use of static scoping, but also because it was designed to be used for teaching programming.
22. Reader macros or read macros are expanded during the reader phase of a LISP language processor
23. ML is a strongly typed language whereas Scheme is essentially typeless. ML uses a syntax that is more closely related to that of an imperative language than that of LISP
24. Evaluation environment stores the names of all implicitly and explicitly declared identifiers in a program, along with their types.

Problem Set
2. fun function_name (formal parameters) = expression;
4. Characteristics of Haskell

  • functions in Haskell can be overloaded
  • nonstrict semantics are used in Haskell
  • Haskell is a pure functional programming language
7. 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.

Answers of Concepts of Programming Languages Chapter 14

Review Questions
2. An exception is raised when its associated event occurs
3. Advantages to having exception handling built into a language :

  • Without exception handling, the code required to detect error conditions can considerably clutter a program
  • Save development costs, program size, and program complexity
7. All of them are gathered together in an exception clause
10. Four exceptions defined in the default package, Standard :
  • Constraint_Error
  • Program_Error
  • Storage_Error
  • Tasking_Error
11. Yes
12. Disabling run-time checks
13. Problems with Ada's exception handling :
  • the propagation model
  • the inadequacy of exception handling for tasks
  • when supporting OOP, its exception handling was not extended to deal with the new constructs
15. Container classes
16. Math library functions
18. After a handler has completed its execution, control flows to the first statement following the try construct

Problem Set
1. The early programming languages, when the error occurs, the error is transferred to the operating system. The typical OS reaction to a run-time error is to display a diagnostic message.
2. Java compilers usually generate code to check the correctness of every subscript expression. In C subscript ranges are not checked because the cost of such checking was not believed to be worth the benefit of detecting such errors
4. Three alternatives for dealing with checked exception in Java :
  • It can catch the exception and handle it
  • It can catch the exception and throw an exception that is listed in its own throws clause
  • It could declare the exception in its own throws clause and not handle it, which effectively propagates the exception to an enclosing try clause, if there is one, or to the method's caller, if there is no enclosing try clause.

Answers of Concepts of Programming Languages Chapter 13

Review Questions
1. Instruction level, statement level, unit level,  and program level
2. SIMD : computers that have multiple processors that execute the same instruction simultaneously
3. MIMD: computers that have multiple processors that operate independently but whose operations can be synchronized
5. Unit level concurrency
6. Vector processors have groups of registers that store the operands of a vector operation in which the same instruction is executed on the whole group of operands simultaneously
8. Scheduler manages the sharing of processors among the tasks.
10. A task is in the blocked state is when the task has been running, but the execution was interrupted by one of several different events
11. Three characteristics of tasks distinguish them from subprograms are :

  • a task may be implicitly started, whereas  a subprogram must be explicitly called
  • when a program unit invokes a task, in some cases it need not wait for the task to complete its execution before continuing its own
  • when the execution of a task is completed, control may or may not return to the unit that started the execution
12. Heavyweight task is the task executed in its own address space, while lightweight task executes in the same address space.
15. Five different states of task :
  • New
  • Ready
  • Running
  • Blocked
  • Dead
16. A task descriptor is a data structure that stores all of the relevant information about the execution state of a task
17. A guard is a linguistic device that allows the guarded code to be executed only when a specified condition is true
19. Competition and cooperation synchronization
24. Concurrent Pascal, Modula, CSP/k and Mesa
30. terminate clause is used to end the execution of a task
35. The yield method is a request from the running thread to surrender the processor voluntarily

Problem Set
1. Because two or more tasks are racing to use the shared resource and the behavior of the program depends on which task arrives first
7 & 8. Comparisons between C# and Java : 
  • C#'s method can be run in its own thread. In Java, only methods named run can run in their own threads.
  • Java supports actor threads, but C# supports both actor and server threads.
  • Thread termination is also cleaner with C$
  • Synchronization in C# is more sophisticated

Answers of Concepts of Programming Languages Chapter 12

Review Questions
1. CLOS, F#
2. Problems with programming with abstract data types are :

  • The modifications require changes to all client programs
  • the type definitions are all independent and are at the same level
3. Inheritance offers the reuse of the ADT and provides framework for the definition of hierarchies of related classes that can reflect the descendant relationships in the problem space
4. Message protocol is the entire collection of methods of an object
7. Dynamic dispatch is dynamic binding of messages to method definitions
8. The protocol of method in a class is called abstract method. Abstract class is the class that has at least one abstract method
9. Design issues for OOP are
  • The exclusivity of objects
  • Are subclasses subtypes?
  • Single and Multiple Inheritance
  • Allocation and Deallocation of Objects
  • Dynamic and Static Binding
  • Nested Classes
  • Initialization of Objects
11. Message protocol is the entire collection of methods of an object
12. All Smalltalk objects are allocated from the heap
14. The only type checking in Smalltalk is dynamic, and the only type error occurs when a message is sent to an object that has no matching method
15. Single inheritance
16. The Smalltalk user interface has had an important impact on computing : the integrated use of windows, mouse-pointing devices and pop-up and pull-down menus, and also the advancement of OO.
19. Heap-dynamic objects are deallocated using delete operator in C++
23. The public and protected members of a base class are also public and protected, respectively in public-derived class. In a private-derived class, both the public and protected member of the base class are private

Problem Set
1. Java does not support private and protected derivations like in C++
7. If a class attempts to implement two interfaces and both define methods that have the same name and protocol, there is no way to implement both in the class
9. class Base {
       void move()

    class Sub : public Base{
        void move()

10. Inheritance offers the reuse of the ADT and provides framework for the definition of hierarchies of related classes that can reflect the descendant relationships in the problem space

Answers of Concepts of Programming Languages Chapter 11

Review Questions
1. The two fundamental kinds of abstraction are process abstraction and data abstraction
2. Abstract data type is a data type that satisfies the following conditions :

  • 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
  • the declarations of the type and the protocols of the operations on objects of the type, which provide the type's interface, are contained in a single syntactic unit.
4. A facility for defining abstract data type in a language must provide a syntactic unit that encloses the declaration of the type and the prototypes of the subprograms that implement the operations on objects of the type.
5. The design issues for ADT are
  • the form of 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
  • the language designer must decide whether the specification of the type is physically separate from its implementation
7. The private part is visible to the compiler
8. The semantic difference is that objects of a type that is declared limited private have no built-in operations.
9. Package specifications provide the interface of the encapsulation and the body package provides the implementation of most of the entities named in the associated package specification
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 entities from the named package.
12. C++ classes are types, Ada packages are more generalized encapsulations that can define any number of types.
14. Member function of a C++ class can be defined in two distinct ways : the complete definition can appear in the class, or only in its header.
15. Destructors are often used 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
16. No value returned

Problem Set
8. The drawbacks of using user-defined generic classes :
  • they cannot store primitives
  • the elements cannot be indexed
9. The default constructor is called instead
10. The two conditions are 
  • 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
  • the declarations of the type and the protocols of the operations on objects of the type, which provide the type's interface, are contained in a single syntactic unit.
11. Because C# uses garbage collection for most of its heap objects
12. Classes in Ruby are made dynamic by simply including additional class definitions that specify the new members.

Answers of Concepts of Programming Languages Chapter 10

Review Questions
1. Subprograms cannot be nested and all local variables are static
4. The task of linker is put the executable programs together.
5. The reason why implementing subprograms with stack-dynamic local variables is more difficult :

  • 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
6. Activation record is the format of noncode part of a subprogram, while activation record instance is a concrete example of an activation record. 
11. EP stands for environment pointer. EP is used to access parameters and local variables during the execution of a subprogram.