Tuesday, January 16, 2018

Session 13

Session 13
Saturday, 13 January 2018

Today is the last session before the final exam. This session talks about "Logic Programming Language". This session, Miss Yanfi make a mind-map/concept-map for us.


Programs in logic languages are expressed in a form of symbolic logic. Symbolic logic is logic which can be used for the basic needs of formal logic.

Objects in propositions are represented by simple terms: either constants or variables. Atomic propositions consist of compound terms,  elements of a mathematical relation, written like a mathematical function. 

Declarative semantics, there is a simple way to determine the meaning of each statement, simpler than the semantics of imperative languages.
Programming is nonprocedural. Programs do not state now a result is to be computed, but rather the form of the result.

The origin of prolog:
• University of Aix-Marseille (Calmerauer & Roussel)
– Natural language processing.
• University of Edinburgh (Kowalski)
– Automated theorem proving.

Term is a constant, variable, or structure. Constant is an atom or an integer. Atom is symbolic value of Prolog. Atom consists of either a string of letters, digits, and underscores beginning with a lowercase letter or a string of printable ASCII characters delimited by apostrophes.

Variable is any string of letters, digits, and underscores beginning with an uppercase letter. Instantiation is binding of a variable to a value, lasts only as long as it takes to satisfy one complete goal. Structure represents atomic proposition.

Fact Statements and Rule Statements are used for the hypothesis. The different is Fact Statements are headless horn clause and Rule Statements are headed horn clause. Goal Statements are statements that are in form of proposition that we want system to prove or disprove.

Approaches :
• Matching is the process of proving a proposition.
• Proving a subgoal is called satisfying the subgoal.
• Bottom-up resolution, forward chaining.
• Top-down resolution, backward chaining.
• Prolog implementations use backward chaining.

When goal has more than one subgoal, can use either Depth-first search or Breadth-first search. Prolog uses depth-first search, can be done with fewer computer resources. 

Backtracking is reconsidering previous subgoal to find an alternative solution if fail to show truth of one of subgoals in a goal with multiple subgoals. Backtracking can take lots of time and space.

Trace is built-in structure that displays instantiations at each step. Tracing model of execution - four events:
– Call (beginning of attempt to satisfy goal)
– Exit (when a goal has been satisfied)
– Redo (when backtrack occurs)
–Fail (when goal fails)

Application of Logic Programming :
• Relational database management systems.
• Expert systems.
• Natural language processing.

Thats all for today session.

Saturday, January 13, 2018

Session 12 - GSLC

Session 12 - GSLC
Saturday, 6 January 2018

This session is GSLC session, so Miss Yanfi give us assignment. The Questions are :
1. What is the different between a language with exception handling and without exception handling? 2. Define exception, exception handler, raising an exception, disabling an exception, continuation, finalization, and built-in exception.
3. What are the alternatives of exception handling?
4. What are the advantages of having support for exception handling built-in to a language?
5. What is tail recursion?
 6. What are the differences between functional and imperative languages?
7. What is the basic concept of declarative semantics?
 8. Explain about the rule statements.
9. What are the differences between depth-first search and breadth-first search?
10. Explain the negation problem with Prolog. Why this is a limitation?

And my answers are:

1. In a language with exception handling

- Programs are allowed to trap some exceptions, thereby providing the possibility of fixing the problem and continuing.

In a language without exception handling

- When an exception occurs, control goes to the operating system, where a message is displayed and the program is terminated.

2. - Exception : any unusual event, erroneous or not, that is detectable by either hardware or software and that may require special processing.

– Exception handler : a code unit which processes an exception.

– Raising an exception : When a event associated with an exception occurs.

– Disabling an exception : Ignoring a certain hardware-detectable exceptions.

– Continuation : Control transfer to somewhere in the program outside of the handler code or program might terminate .

– Finalization : ability to complete some computation regardless of how subprogram execution terminates.

– Built-in exception : Exception that is not made by the user, but rather comes as default.

3. Alternatives:

– Send an auxiliary parameter or use the return value to indicate the return status of a subprogram.

– Pass a label parameter to all subprograms (error return is to the passed label).

– Pass an exception handling subprogram to all subprograms.

4. - Error detection code is tedious to write and it clutters the program.

- Exception handling encourages programmers to consider many different possible errors.

- Exception propagation allows a high level of reuse of exception handling code.

5. Tail recursive is a special kind of recursion where the recursive call is the very last thing in the function
6. •Imperative Languages:

–Efficient execution

–Complex semantics

–Complex syntax

–Concurrency is programmer designed

•Functional Languages:

–Simple semantics

–Simple syntax

–Less efficient execution

–Programs can automatically be made concurrent 

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

8. Rule statements are used for the hypotheses and headed Horn clause

•Right side: antecedent (if part)

–May be single term or conjunction

•Left side: consequent (then part)

–Must be single term

9. – Depth-first search: find a complete proof for the first subgoal before working on others

– Breadth-first search: work on all subgoals in parallel

10. The negation problem: Anything not stated in the database is assumed to be false.
Intrinsic limitations: It is easy to state a sort process in logic, but difficult to actually do—it doesn’t know how to sort.

Wednesday, January 10, 2018

Session 11

Session 11
Saturday, 16 December 2017

This is the last session in 2017 year. This session talks about exception handling and event handling. 

In a language without exception handling:
When an exception occurs, control goes to the operating system, where a message is displayed and the program is terminated.

In a language with exception handling:
Programs are allowed to trap some exceptions, thereby providing the possibility of fixing the problem and continuing.

An exception is any unusual event, either erroneous or not, detectable by either hardware or software, that may require special processing. The special processing that may be required after detection of an exception is called exception handling. The exception handling code unit is called an exception handler.

Exception Handling Alternatives:
–Send an auxiliary parameter or use the return value to indicate the return status of a subprogram.
–Pass a label parameter to all subprograms (error return is to the passed label).
–Pass an exception handling subprogram to all subprograms.

Advantages of built-in Exception Handling :
•Error detection code is tedious to write and it clutters the program.
•Exception handling encourages programmers to consider many different possible errors.
•Exception propagation allows a high level of reuse of exception handling code.

Catch is the name of all handlers--it is an overloaded name, so the formal parameter of each must be unique.
Exceptions are all raised explicitly by the statement:
throw [expression];

An unhandled exception is propagated to the caller of the function in which it is raised. If no handler is found, default handler is called. After a handler completes its execution, control flows to the first statement after the last handler in the sequence of handlers of which it is an element.

An event is a notification that something specific has occurred, such as a mouse click on a graphical button. The event handler is a segment of code that is executed in response to an event.

That's all for this session. 

Session 10

Session 10
Saturday, 6 January 2018

Miss Yanni has business on 9 december and decided to change the class date to 6 january 2018 from 9 december 2017. Today session talks about concurrency. 

Concurrency can occur at four levels:
  • Machine instruction level.
  • High-level language statement level.
  • Unit level.
  • Program level.
A task/process/thread is a program unit that can be in concurrent execution with other program units. Tasks usually work together. There're 2 general categories of tasks, such as Heavyweight tasks and lightweight tasks. Heavyweight tasks execute in their own address space and lightweight tasks all run in the same address space - more efficient. A task is disjoint if it does not communicate with or affect the execution of any other task in the program in any way. 


A mechanism that controls the order in which tasks execute is called task synchronization. There's 2 kind of synchronization : cooperation synchronization and competition synchronization. Cooperation synchronization means task A must wait for task B to complete specific activity before task A can continue its execution. Competition synchronization means two or more tasks must use some resource that cannot be simultaneously used. For task synchronization, task communication is necessary and provided by shared nonlocal variables, parameters, and message passing.

Providing those 2 synchronization requires a mechanism for delaying task execution. Those task execution control is maintained by a program that is called the scheduler. 

Task execution states :
  • New - created but not yet started
  • Ready - ready to run but not currently running (no available processor)
  • Running 
  • Blocked - has been running, but cannot now continue (usually waiting for some event to occur)
  • Dead - no longer active in any sense

A characteristic that a program unit may or may not eventually complete its execution is called liveness. If all tasks in a concurrent environment lose their liveness, it is called deadlock.

Methods of providing synchronization are semaphores, monitors, and message passing. 

Semaphore is a data structure consisting of a counter and a queue for storing task descriptors(data structure that stores all of the relevant information about the execution state of the task).

Monitor is an abstract data type for shared data. Message passing is a general model for concurrency.

That's all for this session.

Saturday, December 30, 2017

Session 9

Session 9
Saturday, 2 desember 2017

Today is my group's turn to present today's topic "Object Oriented Programming" but because Miss Yanfi made a mistake and list us to present session 7's topic "Abstract Data Type" so Miss Yanfi gave us option to choose between session 7 "Abstract Data Type" or session 8 "Object Oriented Programming". My group chose to present session 7 "Abstract Data Type". Today we discuss about The Concept of Abstraction, Introduction to Data Abstraction, Language Examples, Parameterized Abstract Data Types, Encapsulation Constructs, and Naming Encapsulations. After we explain the topics, there were some questions. We were a little confused about the answers for the questions and ask some of it to Miss Yanfi. On this session there's also mind map that Miss Yanfi made for us.

This session talks about the introduction, Object-Oriented Programming, Design Issues for Object-Oriented Languages, Support for Object-Oriented Programming in C++, and The Implementation of Object-Oriented Constructs.

3 major language features :

  • Abstract data type.
  • Inheritance.
  • Polymorphism.
Inheritance allows new classes defined in terms of existing ones, i.e., by allowing them to inherit common parts. Inheritance addresses both of the above concerns--reuse ADTs after minor changes and define classes in a hierarchy.

Three ways a class can differ from its parent:
1. The parent class can define some of its variables or methods to have private access, which means they will not be visible in the subclass.
2. The subclass can add variables and/or methods to those inherited from the parent.
3. The subclass can modify the behavior of one or more of its inherited methods.

A polymorphic variable can be defined in a class that is able to reference (or point to) objects of the class and objects of any of its descendants.

Design Issues for OOP Language :
•The Exclusivity of Objects.
•Are Subclasses Subtypes?
•Single and Multiple Inheritance.
•Object Allocation and Deallocation.
•Dynamic and Static Binding.
•Nested Classes.
•Initialization of Objects.

That's all for this session.

Friday, December 29, 2017

Session 8 - GSLC

Session 8
Saturday, 25 November 2017

Today is GSLC session. Miss Yanfi gave us some questions to answer on the binusmaya's forum.
Here are the questions:

1. What are the similarities of and the differences between Java Packages and C++ Namespace?
2. Explain the dangers of C's approach to encapsulation.

And these are my answers that i wrote on the forum:

1. Similarity : 
- Java uses packages to group classes. C++ uses namespace to group related function and classes. 
- Java package and c++ namespace both make the code cleaner and less redundant. 
- Java package and c++ namespace both provide breakup for class names. 
- Java package and c++ namespace are both abstract container for classes. 

Difference : 
- Java package cant be nested. c++ namespace can be nested. 
- C++ namespace are just used for partitioning names to avoid collisions. java package are used for modules, the naming aspect is just a part of it. 
- In java you can apply various access specifiers to classes which will have impact on your package. these type of access specifiers are not applicable to namespace in C++. 

2. The main problem is that the biggest part of encapsulation is done via hiding, rather than protection. This is achieved through definition hiding: a header file is preprocessed (which is a synonym for copy-pasted) into the implementation file. Anyone with this header file will be able to access any method or public variable of a the client related to the header, left apart any "static" method / variable. The documentation of the dependence of the client program on the library (and its header file) is lost. The author of the library could change the header file and the implementation file, but the client could attempt to use the new implementation file (not realizing it had changed) but with the old header file, which the user had copied into his or her client program.

Monday, November 27, 2017

Session 7

Session 7
Thursday, 2 November 2017


Today is the last session of Programming Language Concept before mid exam. Usually, Programming Language Concept's session is on Saturday but miss Yanfi has another business to do so, the seventh session is moved to Thursday. On this session, there's only one group presentation for preparation of mid exam. Today's topic is "Subprogram".

After the group presentation, miss Yanfi discuss the answer for the last session exercise. Miss Yanfi also explained again the grammar for small language, simple assignment statement and an ambiguous grammar for expression.

This session is discussing about subprograms. The topics are Introduction, Fundamentals of Subprograms, Local Referencing Environments, Parameter-Passing Methods, Parameters That Are Subprograms, Calling Subprograms Indirectly, Overloaded Subprograms, Generic Subprograms, User-Defined Overloaded Operators, Closures, and Coroutines.

Two fundamentals of abstraction are process abstraction and data abstraction. Local variable can be stack-dynamic and static. Each type of variable has their own advantages and disadvantages.

There are 3 type of parameter passing : In mode(pass-by-value), out mode (pass-by-result), and inout mode (pass-by-value-result, pass-by-reference, pass-by-name).


An overloaded subprogram is one that has the same name as another subprogram in the same referencing environment.  A generic or polymorphic subprogram takes parameters of different types on different activations.

A closure is a subprogram and the referencing environment where it was defined.  A coroutine is a subprogram that has multiple entries and controls them itself – supported directly in Lua. Also called symmetric control: caller and called coroutines are on a more equal basis. A coroutine call is named a resume.

This is all for today's session.