Author Archive
Introduction to Erlang : Typing
In this post I will present you the data typing in Erlang.
Dynamic Typing
Erlang is a dynamic typing programming language. That means that when “declaring” a variable you do not need to statically specify the type it will be (as in static typing languages). Read more about dynamic typing here. For example, this is how you would declare and initialize an integer in C (static typing):
int i = 17; |
while in Erlang you would do: (we will see how to declare variables in a while)
I = 17. |
This approach has both advantages and disadvantages. For example, when programming, it is fast and convenient not to declare the variables’ types, but in big projects it can lead to code readability problems unless well documented.
Variable Declaration
Erlang is heavily influnced by Prolog, so Prolog programmers should be ready to discover several commonalities. As with Prolog, the variable declaration is implicit; every character sequence generated by the regular expression [A-Z_]([0-9a-zA-Z_]*) is a variable. Some examples are A, Ab, A_b, Ab1, _, _A_b3. Just to mention that the ones starting with “_” has a special meaning; they are “don’t care” variables. When you use them, the value they will take will probably not be used later. Something like place keepers. You will meet them again and again, so don’t worry for now.
Variable Assignement
Another importand characteristic that Erlang inherited from Prolog is binding with pattern matching. In a nutshell, a value is not assigned to a variable, but bound with pattern matching. The most important consequence of this is that variables in Erlang are single assignement. Once bound to a value, their value cannot change for their lifetime. For example, in an emulator try the following:
1> A = 10. 10 2> A = 11. |
The output you will get is:
** exception error: no match of right hand side value 11
What happens is that A is bound to the value 10, so Erlang tries to pattern match 10 with the value 11, which is impossible.
Next
Since I want to keep the posts rather small, I will break this one here and I will present the actual Erlang types on the following post(s).
Windows from version 1 to version 7..

Windows 1
Opera Software makes fun of Apple’s Mac App Store’s weird decision
![]()
Opera was the first non-native browser to be available for download in Apple’s Mac App Store. Though, Apple judged that the Opera browser is “inappropriate” for people younger than 17 years old.
Opera Software “accepted” this weird decision with a humorous/satiric press release:
This week, the Opera web browser became the first non-native browser made available in Apple’s Mac App Store, but only for those over seventeen years of age. Jan Standal, VP of Desktop Products for Opera Software, is surprised.
“I’m very concerned,” says Standal. “Seventeen is very young, and I am not sure if, at that age, people are ready to use such an application. It’s very fast, you know, and it has a lot of features. I think the download requirement should be at least 18.”
For those under 17, there is a workaround. Just visit www.opera.com and download it. We do not ask for your age or your credit card number. Please, get your parents’ permission before using this browser.
Structures and Memory Consumption in C
Motivation
The way you design you structures in C can have a (significant) impact on the size they occupy in memory!
Memory structure of a structure
A structure occupies contiguous space in memory. Though, in order to provide efficient access to the structure’s fields, C uses padding. In other words, the fields are aligned to the memory words.
Example
In a system with:
word : 4 byteschar : 1 byteint : 4 bytes
without padding would be:
char (8bit) |
int (32bit) |
|---|
and since the word size is 4 bytes the integer would belong to 2 different words, so in order to access it, two memory accesses would be necessary.
In order to avoid it, the actual memory organization is:
char (8bit) |
padding (24bit) |
int (32bit) |
|---|
The Possible Problem
A bad designed structure can possible occupy more space than needed.
Example
Take a look at the following structure:
struct bad { char c1; int i1; char c2; }; |
One would possibly say that since 1 + 4 + 1 = 6 bytes is the total size of the fields, 2 words = 8 bytes will be needed to store it. This is not true. Due to the padding we have:
c1 (8bit) |
padding (24bit) |
i1 (32bit) |
c2 (8bit) |
padding (24bit) |
|---|
3 words = 12 bytes, 4 more bytes than necessary.
Solution
Just take into account how the types fit together:
struct good { char c1; //c1 + c2 = 2 bytes char c2; int i1; }; |
This design needs the minimum number of 2 words = 8 bytes.
Outcome
The bigger the structure gets, the more space you can lose.. So, take care of it while designing the structures!
Introduction to Erlang : Installing Erlang
About Erlang
Erlang is a functional programming language which has many features more commonly associated with an operating system than with a programming language: concurrent processes, scheduling, memory management, distribution, networking, etc.
The initial open-source Erlang release contains the implementation of Erlang, as well as a large part of Ericsson’s middleware for building distributed high-availability systems.
Read the rest of this entry »
Not P==NP for now..
Some time ago (January 19, 2011), Vladimir Romanov announced that he had found a polynomial time solution for the 3-SAT NP-Complete problem. As I mentioned on the first related post, if this was true it would immediately suggest that P==NP.. A nice article about what would be the implications of this equality can be found in Wikipedia.
The time for such a proof (or the opposite one, which is consider to be more probable) has not come yet. Yesterday, with a comment to his blog, Vladimir Romanov announced that there is a problem with the solution that need to be corrected:
Thank you for your attention to my work. You’d better suspend your investigations.
A shortcoming possibly exists in the filtration procedure which requires an amendment.Best regards,
V. R.
Introduction to Erlang post series
While I was writing my first actual (and extremely delayed :-S) article for the Parallelizing simple algorithms series, I realized that since Erlang is not a popular programming language it would be nice to start an Introduction to Erlang post series. I consider Erlang as a must-know language for an engineer that works with distributed systems and parallel programming. Believe me, in several cases, Erlang is a problem solver!
I will try to keep the posts short and example based. An approximation of the posts that I intend to write is:
- Basics: how to get a working Erlang environemt
- Basic Types: integers, floats, …
- Modules and Compiling: how to write and compile a module
- Functions: how to delcare functions
- Library Functions & BIFs
- Lists: list manipulation
- Processes: how to create new processes
- Message Passing: how to send messages between processes
- Debugging: how to debug Erlang programms
- Records: how to use records
I will keep this list updated in case that I come up with new ideas!
I hope I will convince you that Erlang worths every software engineer’s attention..
Parallelizing simple algorithms : Fibonacci
It took me a little more than I expected, but finally I managed to write the first post for the Parallelizing simple algorithms series.
As I “promised”, I will start these series by parallelizing the Fibonacci Number sequence generation. As you probably already know, Fibonacci numbers are the integer sequence produced by the following relationship:
F0= 0 F1= 1 Fn= Fn-2+ Fn-1
The resulting sequence is: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, . . .
