Saturday, March 13, 2010

How to restore Grub in Ubuntu

Boot up your live CD
In the desktop, open terminal (Applications -> Accessories -> Terminal).

sudo grub

This will set it to grub mode

find /boot/grub/stage1

This will locate your boot partition. If you already know the location, you can ignore this step.

root (hd0,0)

Replace the (hd0,0) by your boot partition number. If your Ubuntu is installed in the second partition, then change it to (hd0,1)

setup (hd0)
quit

Reboot your system. You should be able to access the Grub bootloader now.

Thursday, March 11, 2010

Important keywords about functional programming

Pure function:
A function is said to be pure if a function produces the same result when evaluating with same argument(s). Function result should not depend on hidden values or state that may change the result of program. We can say that a pure function depends only on its argument(s). Example Sin(x), Sizeof()...etc

Reactive Systems:
Reactive systems are systems whose role is to maintain an ongoing interaction with their environment at specified rate rather than produce some final value upon termination." Usually all embedded systems and industrial "Real time" systems are reactive in nature. The main feature of these systems are:
  • They involve concurrency.
  • They are usually deterministic.
  • They are generally made of both H/W and S/W.

Referential Transparency:
Referential transparency, a term commonly used in functional programming, means that a function/method invocation can be replaces by its return value without changing algorithm or program semantics. Ex F(x)=x +1 in this function for a given value of x say 5, it can be replaced by 6 easily. This can only be true when
  • function simply compute a value.
  • function is independent of temporal context and has no side effect.
The main advantage of referential transparency is that it makes it much easier to reason about programs, and to apply program transformations... including optimizations and partial evaluations at compile-time (since if a computation has no side-effects, then it doesn't matter whether you calculate it now or later).

Referential Opaqueness:
This concept is just opposite of referential transparent. Functions can't be replaced by their value because they depend on external things. For example if a function getinput() is reading from a file or keyboard then it's output can not be predict because file can be changed or user can enter any char/word/sentence.
Another example is
int a= 10; //global variable
func(int x)
{
return x+a;
}
ny
This function will not always add 10 to given value of x because as a is global it can be changed by other function or assignment.

Why Functional Programming is Important

Functional programming is very important aspect in programming. It is a new way of thinking. This programming style promotes modularity, reusability, and one of the more important aspect readability. Programs are small in this style of programming like for a given problem if we write a program in any imperative language (C, C++, java) then same program in functional languages( Haskell, Erlang) can be written in 1/5 LOC. Some important points are:
  • We focus on What to do rather than how to do.
  • Program looks like a mathematical expression