Sunday, July 15, 2012

Tuesday, May 17, 2011

First Hello World with Erlang

I’m going to enter a file that looks like this:

-module(hello).
-export([mirror/1]).
mirror(Something) -> Something.


The first line defines the name of the module.
The second line defines a function that you want to use outside of the module.
The function is called mirror, and the /1 means it has one parameter.
Finally, you get to the function itself. (Prolog-style rule).
The function definition names the function and determines the
arguments.
Afterward, you have the -> symbol, which simply returns
the first argument.
In the console from the
same directory that has the code file. I can then compile it like this:

Eshell V5.8.3 (abort with ^G)
1>
1>
1> c(hello).
{ok,hello}
2>
2> hello:mirror(hello_world).
hello_world
3>
3>
3> hello:mirror(100).
100
4>
4
>


Notice that it is not enough to have the function name alone. You also
need to include the module name, followed by a colon.

Done

Steps to build and install Erlang on Linux ubuntu

Install all dependencies to build and install Erlang from source.

First  : 
Assume to install GCC and C++ Compiler.
 
#sudo apt-get install build-essential g++

Install Ncurses development libraries
#sudo apt-get install libncurses5-dev

Install m4 package.
#sudo apt-get install m4

Install SSL development libraries.
#sudo apt-get install libssl-dev

Install unixODBC package with it’s development package.
#sudo apt-get install unixodbc unixodbc-dev

Install Gd2 libraries and it’s development libraries.
#sudo apt-get install libgd2-xpm libgd2-xpm-dev

Install documentation tools.
#sudo apt-get install xsltproc


Install a recent jdk version
#sudo apt-get install sun-java6-jdk
 
We start building Erlang.

#tar -xzvf otp_src_R14B02.tar.gz



Go to extraction directory the configure installation.

#cd otp_src_R14B02 
 
#./configure 
 
#sudo su 

Run make and sudo make install in current directory.
 
#make
 
#make install


Restart the Terminal...

Type erl and enjoy erlang

root@ubuntu:/home/kernelmanz# erl
Erlang R14B02 (erts-5.8.3) [source] [64-bit] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:false]


Eshell V5.8.3  (abort with ^G)
 

1> 1+1.
2
2>
 

Saturday, May 14, 2011

Install IO on Linux

Generally on my development machine when I compile from source I like to install locally to my home directory rather than system wide. This way sudo privileges are not needed plus I just like the idea of keeping these items close to home.
First Io requires the cmake build system so make sure that is available.

$ sudo apt-get install cmake
 
Next download and extract the source code.
$ wget --no-check-certificate 
http://github.com/stevedekorte/io/zipball/master -O io-lang.zip 
 
$ unzip io-lang.zip
$ cd stevedekorte-io-[hash] 

Io provides a build script, however it is setup to install the language to /usr/local. Since I want it to go in $HOME/local you just need to modify that file. Here is a quick one liner:
$ sed -i -e 's/^INSTALL_PREFIX="\/usr\/local/INSTALL_PREFIX=
"$HOME\/local/' build.sh

Now build and install.

$ ./build.sh
$ ./build.sh install


Since we are installing into a location our OS doesn’t really know about, we need to configure a few paths.
$ vim ~/.bashrc
export PATH="${HOME}/local/bin:${PATH}"
export LD_LIBRARY_PATH="${HOME}/local/lib:${LD_LIBRARY_PATH}"
 
# You might want these too
export LD_RUN_PATH=$LD_LIBRARY_PATH
export CPPFLAGS="-I${HOME}/local/include"
export CXXFLAGS=$CPPFLAGS
export CFLAGS=$CPPFLAGS
export MANPATH="${HOME}/local/share/man:${MANPATH}"
 
Lastly restart your shell and type ‘io’ and Enjoy!