2013-11-06

A little survey

https://docs.google.com/forms/d/1dzQ_jxOowFQG1BbhlGeQ7LznuIh0QgtLwvjrRx_1pvo/viewform

2013-06-28

Note



Multi entry subprogram : Co routine

Return type : is not a parameter profile

Advantages of using keyword parameter : can appear in any order

Disadvantages of using keyword parameter : user have to know the name of the formal parameter

Value of default formal parameter in C++ is located at : the end

Most imperative have function and procedure. Language that does not have procedure : Pascal

Language below that have stack dynamic local variable : Java

Recursive subprogram is first designed in : Algol

Pass by copy is the other name for : pass by value-result

Implementation of I/O parameter model is : Pass by name, pass by reference, pass by value-result

Aliases that happen in pass by reference can be eliminated using : pass by name

Characteristic of pass by name is : flexible but slow

Overloaded subprogram is also called : ad hoc polymorphism

If a subprogram have a unique protocol, then it is called : overloaded subprogram

Side effect problem could be avoided using : in-out mode parameter

The only language that can return any type value is : Ada

The first language that use co-routine is : Simula 67

One of the characteristic of co-routine is : multi-entry

Late binding happen at : pass by name

Variable dynamically allocated : is NOT characteristic of subprogram on FORTRAN 77

Subprogram linkage included : sub program call and return

Activation record on FORTRAN 77 only have one instance because : no recursion

Two main methods to access non-local variable in static scope is : static chain and display

The pair that is used to show actual reference of non-local variable on static scope is : chain offset, local offset

Disadvantage of using static chain to access non-local variable is : the cost to point to variable and hard to estimate the variable cost.

Display : collection of static link that is stored in stack array

To refer to local variable : Display is as fast as static chain

When referring non-local variable, static chain is fasten then display : if the static away level is the same

Compare with deep access, shallow access is : much faster and less costly

Characteristic of dynamic chain is : fast access, fast call

2 different method that is used for passing parameter in language that is similar to Algol is : pass by value, pass by reference

Method that is used to implement block are : parameter-less subprogram and local allocation above ARI

Example of process abstraction are : subprogram, concurrency, and exception handlers

The main feature of ADT are : encapsulation and information hiding

Parametrized ADT in C++ is called : Template Class

Concept of Encapsulation is first implemented by : Simula 67

Function in C++ that is used to give initial value to a new object is : constructor

Simulator : is not an operation that have to be made by ADT designer

Instance on ADT is called : object

Additional feature that differentiate Ada 95 with ada 83 are : protected object and asynchronous communication

Key concept on data abstraction : information hiding

Object modularity : is not the advantages of information hiding

Language which construction did not include information hiding is : SIMULA 67

Encapsulation in Ada is called : Package

C++’s class and Ada’s package are encapsulation

Generic or parametrized ADT in C++ is called : Template

Task : is implicitly started

Data task communication is done through : parameters, message passing and shared non local

Language that use dynamic binding between exception and handler is : PL/I

The first person to suggest the usage of static binding between exception and handler is : J.B. Goodenough

Exception in C++ is raised explicitly through : Throw [expression]

Language that didn’t provide build-in exception is  : c++

Handler on PL/I format :
ON condition [snap]
begin
end

Exception handling first developed in language : PL/I

Scope on C++ handle is specified by : Try construct

Language which design exception is considered weird because it doen’t have a name is : C++

Exception handler usually local on the code where the exception handling appear so it does not need 
parameter. This type didn’t happen in language : Ada, C++, and Java

Exception handling in C++ is NOT designed by : PL/I

Exception handling in C++ is different with Ada in : There exist built in exception and no named user defined exception

Language that force the user designed exception in form of class is : Java

The syntax throw new myException[ ] : is Java

All handler in C++ have the same name, Catch. This case is known as : overloaded name

Exception that is often ignored by user program is : throw able exception

Exception that is not concern with compiler is : unthrowable exception

Language that check array subscript error range are : Ada and Java

Exception handling in C++ is similar to Ada in : Static binding and spread onto function caller

The term monitor is first used by : C.A.J. Hoare

Concurrent Pascal is Wirth Pascal with extra feature except : guard

Instance on monitor is created using : Init statement

Features that is provided by monitor so cooperation synchronization between process happen is : semaphore queue

Two basic characteristic that is provided by the language with concurrency is : mutually exclusive access, competition among task

For distributed system, the best model for concurrency is : Message passing

Category of concurrency are : physical, logical, quasi concurrency

Concurrency can happen at these level : Instruction, unit, program

Co-routine = quasi concurrency

Binary semaphore is : access

2013-06-27

Programming Language Concept (16)

Book : Concept of Programming Language
Page 759
Review Question

1. What are the 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 ?
- functor and and ordered list of of parameters


3. What are the two modes in which a proposition can be stated ?
- one in which a proposition is defined to be true and one in which that the proposition is something to be determined.


4. What is general form of a proposition in clausal form ?
-B1 U B2 U . . . U Bn C A1 n A2 n . . . n Am


5. What are antecedents ? Consequents ?
- Antecedents are right side of a clausal form proposition. Consequent is left side of a clausal form propositions


6. Give general 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 ?
- a. Have a single atomic proposition on the left side
b. empty left side.


9. What does it mean for a language to be nonprocedural ?
- Language in which the programs do not exactly state how a result is to be computed but rather describe the form of the result.



Page 760
Problem Set
1. “All predicate calculus propositions can be algorithmically converted to clausal form”. Is this statement true or false ? Explain.
- True.


8. Critically comment on the following statement : “ Logic programs are nonprocedural”
- It is true, because logical programs use lots of different processes based on its conditions. If a certain logical requirement is true, then a program will execute the corresponding process, instead of procedurally executing the statements.


9. From a book on Prolog, learn and write a description of a monkey-banana prolem. Why does Prolog allow this problem to exist in its implementation ?
- The problem is defined as this : a monkey is in a room. Suspended from the ceiling is a bunch of bananas, beyond the monkey’s reach. However, in the room there are also a chair and a stick. The ceiling is just the right height so that a monkey standing on a chair could knock the bananas down with the stick. The monkey knows how to move around, carry other things around, reach for the bananas, and wave a stick in the air. What is the best sequence of actions for the monkey?
It exists to create a variation in output of Prolog. As Prolog is an AI programming language, a variation might be needed in AI output to make them respond relevant to the situation.

Programming Language Concept (15)

Book : Concept of Programming Language
Page 721
Review Question

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

3.   Atoms and lists were parts of the original LISP.

6.   Simple list is a list which membership of a given atom in a given list that does not include sublists.

7.   REPL stand for read-evaluate-print loop.

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

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

22.  During reader phase of a common LISP language processor,  There is a special kind of macro, named reader macros or read macros, that are expanded.  A reader macro expands a specific character into a string of LISP code. For example, the apostrophe in LISP is a read macro that expands to a call to QUOTE.

24.  What is stored in an ML evaluation environment?
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.

29.  Curried function let new functions can be constructed from them by partial evaluation.

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


35.   A language is nonstrict if it does not have the strict requirement.

43.  What is the syntax of a lambda expression in F#?
The following lambda expression illustrates their syntax:
(fun a b −> a / b)


Page 723
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.
Consider the following example code, which uses the high-order functions filter and map:
let myNums = [1; 2; 3; 4; 5]
let evensTimesFive = myNums

|> List.filter (fun n −> n % 2 = 0)

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
|> List.map (fun n −> 5 * n)

Programming Language Concept (14)

Book : Concept of Programming Language

Page 665
Review Question

2.   An exception is raised when its associated event occurs.
 
3.   The advantages of having support for exception handling builtin 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.
 
9.   An exception handler in Ada can occur in either a  subprogram body, a package body, a task, or a block
 
10.  There are four exceptions that are defined in the default package, Standard:
Constraint_aError
Program_Error
Storage_Error
Tasking_Error

 
12.   The suppress pragma is used to disable certain run-time checks that are parts of the built-in exceptions in Ada.
 
14. The name of all C++ exception handlers is Try clause.
 
15.  The exception out_of_range is thrown by library container classes.
 
16.  The exception overflow_error is thrown by math library functions.
 
32.  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.   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.
 
Page 667  
Problem Set  
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.
 
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.

 
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.

Programming Language Concept (13)

Book : Concept of Programming Language
 
Page 625
Review Question
 1.   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)


2.   In an SIMD computer, each processor has its own local memory. One processor controls the operation of the other processors. Because all of the processors, except the controller, execute the same instruction at the same time, no synchronization is required in the software.

5.   Unit-level concurrency is best supported by MIMD computers.

6.   Vector processor 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.


7.   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.   A scheduler manages the sharing of processors among the tasks. If there were never any interruptions and tasks all had the same priority, the scheduler could simply give each task a time slice, such as 0.1 second, and when a task’s turn came, the scheduler could let it execute on a processor for that amount of time.

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

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

21.   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.   Ada 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.   Sleep method in Java blocks the the thread.

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

36.  The join method in Java is used to force a method to delay its execution until the run method of another thread has completed its execution.

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

56.  The use of spawn primitive of CML is to take the function as its parameter and to create a thread.

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

60.   What is the type of an F# heap-allocated mutatable variable?
A mutable heap-allocated variable is of type ref

63.  The FORALL statement of High-Performance Fortran is to specifies a sequence of assignment statements that may be executed concurrently.

Page 627
Review Question
1. Explain clearly why a race condition can create problems for a system.
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).

2.   The different ways to handle deadlock:
- Ignoring 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 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.