Archive for April 2011

Netbeans 7.0 on Ubuntu Installation – OpenJDK problem

Installation

The installation process is simple:

  1. Download the version you want to install from here.
  2. Navigate to the folder were the .sh file was downloaded.
  3. Give executable permissions to the .sh file.
  4. Execute the installer (.sh) file either pretending sudo command (in order to install it in the default /usr/local/netbeans-7.0 location) or without (in order to install it in the /home/Username/netbeans-7.0/ location)
  5. Use the Graphical Installer to do the installation.

For example:

[~] $ cd ~/Desktop/                                                     # Step 2
[~/Desktop] $ ls -l netbeans-7.0-ml-cpp-linux.sh 
-rw-r--r-- 1 *** *** 45967360 2011-05-03 09:21 netbeans-7.0-ml-cpp-linux.sh
[~/Desktop] $ chmod +x netbeans-7.0-ml-cpp-linux.sh                     # Step 3
[~/Desktop] $ ls -l netbeans-7.0-ml-cpp-linux.sh 
-rwxr-xr-x 1 *** *** 45967360 2011-05-03 09:21 netbeans-7.0-ml-cpp-linux.sh
[~/Desktop] $ sudo ./netbeans-7.0-ml-cpp-linux.sh                       # Step 4
Configuring the installer...
Searching for JVM on the system...
Extracting installation data...
Running the installer wizard...

OpenJDK Problem

The problem with OpenJDK

Configuring the installer...
Searching for JVM on the system...
Extracting installation data...
Running the installer wizard...
null

while installing Netbeans 6.9.1 on Ubuntu is the same for Netbeans 7. Netbeans needs Sun JDK to work, otherwise even the installation wizard (GUI) does not appear.

Read more details about the problem and how to solve it in the post about Netbeans 6.9.1.

Introduction to Erlang : List Comprehension

This entry is part 13 of 16 in the series Introduction to Erlang

List Comprehension

Do you remember the lists:map/2 and lists:filter/2 functions from the previous post? If not, consult the Lists & lists Module post. lists:map(Function, List) returns a new list that results from List after applying the Function to each element. lists:filter(Predicate, List) returns a list that contains only the elements of List for which the call to Predicate returns true.

Both the aforementioned operations are commonly used, as well as their combination; map & filter (does it remind you map & reduce?). Erlang provides this combined functionality using the list comprehension construct.

Format

A list comprehension look like the following:

[Expression || Generators1, Guards1, Generators2, ...]
Generators

As their name suggests, generators create the data used in the filter-map operations. A generator has the Pattern <- Data format, where Data is a list or an expression that results to a list and Pattern is a pattern used to match with the elements of the list. This pattern can be used to disassembly elements. For example, two valid generators are I <- lists:seq(1, 10) and {X, Y} <- [{'A', 'Excellent'}, {'B', 'Good'}, {'C', 'Fair'}].

Expression

The expression specifies the elements of the result. For example, [I || I <- [1, 2, 3]] returns the input list element as is.

Guards

Guards are expressions that return either true or false, the same as the guards we have seen in the previous posts. They apply to the variables that are on the left of the guard and the ones that are accessible due to the scope where the comprehension runs. For example, I <- [1, 2, 3, 4], I rem 2 == 0 is a valid generator - guard combination (the result should be obvious; only the even numbers "pass" the guard's test).
Read the rest of this entry »

Introduction to Erlang : List & lists Module

This entry is part 12 of 16 in the series Introduction to Erlang

List

List is the the most important data type in Erlang, as in every (?) functional programming language. We have seen and used lists in almost every previous post. In this post, I will briefly present the “theory” of lists and then present the Erlang’s lists module and its most important functions.

Definition

A list can be recursively defined as the construct that

  • either is the empty list (denoted as [] in Erlang),
  • or is a cosntruct that its first element is a term (called head) and what remains if the head is removed is a list (called tail)

In Erlang a list of N elements has the [Element1, Element2, ..., ElementN] format (N is called the length of the list). So, [] is the empty list, [1], [{a}] are 1-element lists, [1, 2], [a, {b, c}] are 2-elements lists, etc. As we will see in a while, the format [Element1, Element2, ..., ElementN] is a shorthand for the [Element1 | [Element2 | ... | [ElementN | []] ... ] representation.
Read the rest of this entry »

Introduction to Erlang : BIFs & Predefined Modules

This entry is part 11 of 16 in the series Introduction to Erlang

Built-in Functions (BIFs)

Erlang’s Built-in Functions (shorthand BIFs) are commonly used functions that are intergrated into the Erlang’s VM for performance reasons. Most of them belong to the erlang module, but there are some in other modules, such as lists.

The BIFs can be separated to standard and non-standard. The standard ones are auto-imported; they can be called without the use of the module name prefix (remember the effect of the -import(...) directive). On the other hand, the non-standard ones have to be called following the normal module:function(...) convension. In the erlang module’s man pages (here) the distinction between standard and non-standard is visible by the lack or existence of the erlang (module’s name) prefix.

elrang

abs/1

Arithmetic absolut value of an integer or float.

erlang:append_element/2

Appends an element to a tuple.

apply/2|3

Calls the function passed as a parameter.

atom_to_list/1

Returns a string which corresponds to the text representation of Atom.
Read the rest of this entry »

Introduciton to Erlang : Recursion (2/2)

This entry is part 10 of 16 in the series Introduction to Erlang

Accumulators

In several cases, as with the mlists:length/1 example, the non-tail recursive function can be easily turned to a tail recursive one by using the notion of accumulator. An accumulator is an extra argument introduced to a function in order to aggregate the partial results of the function. It turns the “bottom-up” collection of the final result to “top-down”.

In order to add and initialize the accumulator argument one has to introduce an extra function definition.

tlr(...) ->
    tlr(..., Accumulator_initial_value).
 
% the clause that "breaks" the recursion and
% returns the result
tlr(..., Accumulator) -> 
    Accumulator;
tlr(..., Accumulator) ->
    ...,
    Accumulator_new_value = ...,
    ...,
    trl(..., Accumulator_new_value).

Notice that typically you would only export the tlr/1 function and the tlr/2 would remain for inner-module use and not visible to the module’s users.
Read the rest of this entry »