Archive for the 'languages' Category missing in Ubuntu 10.04?

When programming Haskell, I usually hack in a GHCi interactive session.  So I was surprise when I tried to make a test executable the other day:

ralph@vegeta:~/src/haskell$ ghc --make Hello
[1 of 1] Compiling Main             ( Hello.hs, Hello.o )
Linking Hello ...
/usr/bin/ld: cannot find -lgmp
collect2: ld returned 1 exit status

libgmp is a library for arbitrary precision arithmetic, which is something Haskell does well. So, I was surprise that I was getting this message. The obvious solution is install the Ubuntu package for libgmp:

ralph@vegeta:~/src/haskell$ sudo apt-get install libgmp3c2
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libgmp3c2 is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 44 not upgraded.

Well that was strange!  So, I searched for libgmp on my system:

ralph@vegeta:~/src/haskell$ find /usr/lib/ -name libgmp*

There is no symlink, so I just created one:

ralph@vegeta:~/src/haskell$ cd /usr/lib 
ralph@vegeta:/usr/lib$ sudo ln -s

Now everything compiles and links:

ralph@vegeta:~/src/haskell$ ghc --make Hello
[1 of 1] Compiling Main             ( Hello.hs, Hello.o )
Linking Hello ...

Installing clbuild

After frustration with using an older version of sbcl and using asdf-install, I decided to try clbuild.  clbuild is a shell script that allows me to keep my lisp environment updated.  It is a little different from asdf-install, because it does not download tarballs, it gets the source code directly from their respective source code repositories.

So, the first thing I did was to get clbuild itself.  For some reason, I did not have darcs installed, so I had to install that first on my Kubuntu laptop:

~$ sudo apt-get install darcs

After that, use darcs to get clbuild:

~$ darcs get

Make clbuild executable:

~$ cd clbuild
~/clbuild$ chmod +x clbuild

As far as I can tell, you need to run clbuild from this directory. So, the next step is to do a system check:

~/clbuild$ ./clbulid check

Now, time to get an update to sbcl. With my system, sbcl is natively located in my bin directory:

~/clbuild$ which sbcl
~/clbuild$ sbcl --version
SBCL 1.0.18.debian

Now, using clbuild to download and compile the latest version of sbcl:

~/clbuild$ ./clbuild update sbcl
~/clbuild$ ./clbuild compile-implementation sbcl

After a long wait, an sbcl implementation was placed in ~/clbuild/target/bin. To run it, use clbuild again:

~/clbuild$ ./clbuild lisp
This is SBCL, an implementation of ANSI Common Lisp.
More information about SBCL is available at <;.

So, clbuild is using the newest version, but my older implementation is still there. Next time, I will set up SLIME with Emacs to point to this new target.

Nested Map

I was in the #lisp chat room at Freenode when someone posed a question about performing a map function over a nested lists. This was an interesting problem, so I thought that I would cover it here.

Suppose there was a complex tree of numbers:

((1 2) (3 4))

And you want to map each to a function (let’s say a squaring function) and maintain its structure. This is where a good utility function would be in order. The function must be able to handle trees of an unknown structure. So, the only solution that I know would be to use recursion:

(defun nested-map (fn item)
    (cond ((null item) nil)
          ((atom item)   (funcall fn item))
          ((consp item) (cons (nested-map fn (car item))
                                 (nested-map fn (cdr item))))))

Even though it looks complex, the function seems correct:

CL-USER> (nested-map #'(lambda (x) (* x x))
           '((1 2) (3 4)))
((1 4) (9 16))
CL-USER> (nested-map #'(lambda (x) (* x x))
           '(1 2 (3 4 (5 6 7))))
(1 4 (9 16 (25 36 49)))

I think I’ll keep this in my utility toolkit. I am concerned about the performance, but I won’t worry too much about it until it becomes a problem.

Groovy Baby, Yeah!

groovybabyWorking in mostly M$ shops in the past 10 years or so, coupled with my home projects in the functional languages, I don’t get to do much with Java or the JVM anymore.  But today, it was treated to my first experience in programming in Groovy.  The tool that I use to test SOAP web services, SoapUI, is built upon Java and uses the Groovy as embedded scripting language to manipulate the testing environment.

I must say that it is a pretty neat.  Just using it as a scripting language seem to be natural, almost like Python or Ruby. Even though I did not use any advanced features such as closures, builders, or regular expressions, I hope that I can give it a try some time.

Reading Programming Erlang

A few weeks ago, I received my copy of Joe Armstrong’s Programming Erlang: Software for a Concurrent World.  I was quite impressed.  It was a great introduction on the Erlang programming language and more importantly, concurrent programming. After reading the book, I am not sure if I fully understand it’s true power.  

What do I mean? The idea of having a language that is built for fault-tolerant, distributed, concurrent, mostly real-time applications may come as a pipe dream to some. To me, Erlang is the real deal. It’s simplified view of concurrency makes it easy to create high performance systems.  It’s share-nothing attitude toward memory and communication allows for high process scalability.  The simple fact that Erlang is a functional language allows these two concepts to exist.

There is just no equal in mainstream languages. Some may think that it was designed at some University and it’s nothing but a toy language.  The truth is that Erlang was created by a real company, by career engineers, to solve real world concurrent problems, and used in real products. So, one cannot really use that argument anymore.

 As recommended by the author, I have to read the book again and again.  I hope that I am able to read it again before I receive Real World Haskell in a few weeks.

The Wayback Machine : What I Did 10 Years Ago

The Internet is a wonderful thing, but it has a serious flaw. It has a memory. An unrelenting memory, in fact, that seems to remember things that I have long forgotten. Today, it is common knowledge that you should not publish things on the Web that you would not publish in a novel. Ten years ago, though, the Web was as wild as the American Old West. People were doing some pretty wild things.

So, what brought me to think about what I was doing ten years ago? Well, I found out today that Borland finally sold its CodeGear software tools division after two years of trying. Back in 1998, Borland offered a IDE called C++ Builder. When first introduced C++ Builder was the revolutionary step in Windows application development. That tool help me create some tools quickly that Microsoft C++ could never do.

As great as C++ Builder was, it had limit support for DirectX, the relatively new high performance graphics API from Microsoft. Since multimedia was a hobby of mine, I started experimenting with DirectX in C++ Builder. I started a small site using my ISPs personal web pages and thanks to the Wayback Machine, you can see it for yourself and all its splendor.

As my interests in Free Software grew, OpenGL became my dominate graphics environment on Linux. The site was discontinued sometime in late 2000. It seems that the popularity of Free and Open Source software increase, C++ Builder could not compete. Borland later offered a free (as in beer) command line version of the BCC, the same compiler in C++ Builder, but it was the C++ Builder IDE that made it special. I am sad the unfortunate demise of this product. I wish that Borland would have open sourced C++ Builder to let the community decide its fate. It certainly would have been interesting.

Soup Of Punctuation

Herb Sutter filed this entry earlier this month providing a summary of the March ISO C++ Standards meeting. One of the new features added to C++0X is lambda functions and closures.

So, in his entry, Herb provides an iteration example of writing a collection of objects to the console using a lambda function:

for_each( w.begin(), w.end(),
[]( const Widget& w ) { cout << w << " "; });

And an example of using the std::transform algorithm:

transform( v.begin(), v.end(), output.begin(), []( const Widget& w ) -> AnotherType
return SomeResultCalculatedFrom( w );
} );


I love that fact that one of the main criticisms of Lisp is that there are too many parentheses. After looking at these examples, it seems like C++ and other languages wishes to be Lisp, but are cursed with their own soup of punctuation. It’ll be some time before this C++ syntax sticks, so I’ll just stay on the fence (still hacking Lisp) to see what happens.