Author Archives: esden

Lisp on Embedded Systems

I had a very inspiring conversation today. I was trying to lay out why one should learn Lisp. I found that there are tons of reasons why Lisp is superior to other Languages. But I found some articles in the web that can explain that much better then me. There are some Articles written by Paul Graham that describe the reasons beautifully. For example “If Lisp is So Great” or “Revange of the Nerds“. I can only encourage you to read them.

What I found very interesting is the main statement of these Articles. Popularity of a Language is not the same as greatness as very well explained in the second Article. Another statement is that programming languages are slowly closing up with functionality and paradigms found in lisp. That is also one of the reasons why I started learning it, because I heard about that trend some time ago somewhere in the big depths of the net.

Most articles are stating that Lisp is the way to go to create web applications and financial systems. But I would even go further. I think it is also the way to go for embedded systems. Some people may think that Lisp is too big and too slow to use it for development on embedded systems. But look at your cellphone. It will probably have a JVM (Java Virtual Machine) running on it. What is that thing? It is a full emulation of a system. It runs bytecode. It is slow like hell but people still develop applications for cellphones compleatly written in java. I bet that there are phones that have their entire software written in Java. Now we look at Lisp. I found a comparison between JDK and SBCL here. It really seems that Java is faster and uses up less memory in most cases. At least taking a glimpse on the Graph. But as I already posted before. SBCL is not perfect. But there are developments like “Headless” coming that will better up that situation. On another site I found that the commercial Allegro Common Lisp implementation is the fastest. But sadly I do not see any benchmarks anywhere. And it does not support any embedded system.

I think that even if the benchmarks show that Lisp may be less efficient in speed and memory usage, it is only a matter of time and dedication to change that. But what do you buy with that loss of efficiency anyways. You get a REPL (you can interact with everything in the running program) you get binary upload (you can change the code of a running program) you get macros.

But for the beginning we could start with something more simple then the full fledged Common Lisp on embedded. There is still L (a Common Lisp language subset specially designed for embedded systems) and Mars realtime kernel to run L on. I sadly have not found a project site for that only a paper. I ask myself how much of Lisp goodness it provides.

Next semester I will have to make a project in embedded systems and the topic is not yet fully set. But I hope that I will be able to work towards the target of running lisp on embedded systems. I already asked my Professor about the idea and he is not negative but he still wants to talk about it. So wish me luck. (also I hope that my partners for the project will be willing to work in that direction too)

If you have any pointers and ideas about this topic then do not hesitate. I will appreciate any pointer.

[Update] Corrected minor stylistic mistakes.

Compiling Binaries with sbcl

There is one thing that you really want to have when you are creating programs. You want to create binaries. You can give them to others so that they can run them, without the hassle of compiling your programs by themselves, or you do not want them to see your sourcecode for some strange reason.

When you look at ruby, perl, python or even the all praised Java (do you hear the holy horns play? >_< ) you will see that you always need to install the appropriate one with tons of libraries so that you can run the scripts. I know I know ... I already see you running in my direction with your blades pulled out. There are compilers and packagers out there that can create binaries and you can even create a static binary that runs without the need of additional libraries. But think for yourself are these solutions good? Is it working well? I remember trying gcj. I had a test program of some hundred of very simple and standard java code. It was screaming very loudly "I am not ready to do that, I am too young!" perhaps it is better these days but I can not imagine that it works as it should. I also tried a perl to c converter but it was even more a mess. As you know I am playing around with lisp, common lisp to be exact. As most people I was thinking that it will be the same way it is with the languages mentioned above. But I could not be wrong more. There are compilers and today most of the implementations do not even have an interpreter. Most of them compile the code to at least bytecode. (I know ruby does that too, and Java too ... damn do not pick out every word I say separately) But sbcl for example (my implementation of choice for now) compiles everything. In CMUCL from which SBCL was inherited still has an interpreter additional to the compiler. I wanted to try out how it works with compiling a binary. I first thought that it will work just like with gcc or other command line batch compilers but I once more could not be wrong more. What you do is start SBCL load all libraries you need with "require" or "load" also load your program code and initialize everything you need. Then you run: (sb-ext:save-lisp-and-die "my_binary" :executable t :toplevel 'main-program-function) After that you have "my_binary" on your disk and you can start it on every compatible machine. What it does is saving the state of the lisp with everything that is present at the time you run the command. When you leave out the :executable you get a core file that you can use to run with sbcl -core commandline parameter. The :executable command only adds to the core file the ability to be executed by the operating system. In fact sbcl binary is just this kind of core dump that was created at compiletime of sbcl. The :toplevel keyword says the save function which function should be called the next time the core gets loaded. In most cases it probably will be the main function of your program. But when you think about it a bit more you can imagine how much power it is to be able to say what function is the main function. πŸ˜‰ (I know it from the lowlevel embedded programming side of the world πŸ˜‰ ) But now comes up the Question. It is a coredump so what does it contain? Well there it comes. It contains everything. Really everything including all libraries and the lisp compiler. So when I compile the robots game I introduced in the previous post here I get a binary of 23MB (yes megabytes). That is pretty much. Sure it does not count if you have a really big system that is 100 times bigger but still that sucks somehow. I informed myself and now I know that there is something called "headless" in the works that will enable sbcl to create coredump with an integrated dynamic linker. This will make the binary significantly smaller and when you run your program it will dynamically link the libraries it needs. Just as it should be. Next thing is from the slime world. There is a profiler in the works that will be able to even more optimize the code so that you will be able to create really small binaries. All that is of course only SBCL other, commercial lisp implementations, like LispWorks or Allegro, already have very efficient mechanisms to create such binaries. But as long as you do not need that stuff immediately you can stay on the open source side of the world. πŸ˜‰

I hope that was interesting, and also hope to get some comments. That would encourage me to write more…

Robots in Lisp

I worked a little bit more with lisp. As a side effect I wrote a clone of Robots (a classic bsd game called robots). The idea is to run away from robots that try to hunt you down. You also may teleport yourself if they cornered you but you never know where you land so it may be possible that you land on one of them or on a heap of junk (that one appears when two robots collide). It is pretty much fun to play.

I also managed it to configure my emacs with a beautiful font called proggy tiny. This one required non antialiased drawing. I was able to disable it with (setq mac-allow-anti-aliasing nil) in my .emacs configuration file. I also changed all the relevant faces to use that font but still it did not work properly. Finally I found out that you have to use the size 16pt of the font so that you do not get strange artifacts.

Here you can see the result:

Click on the image to get full version.

You can get the source of robots from my devel server svn repository:

svn co http://repl.esden.net/svn/cl-games/trunk/robots

There is still a lot to do. I am still learning a lot of lisp so the code gets (hopefully) better with the time I am learning. I will have to add asdf package description (asdf is make for lisp). Also packaging should be added and probably I should use CLOS (Common Lisp Object System) and cl-ncurses (ffi (foreign function interface) for ncurses).

There is also a trac for cl-games project you can write tickets in if you find something worthy to add there.

So happy coding and dammit start learning lisp if you have not yet!!!1eleven πŸ˜‰

Common Lisp

Some time ago I listened to a Chaos Radio Express podcast dealing with Dylan.

Dylan is a pretty nice language developed by a research group leaded by Apple Computers. The idea was to create a better lisp language. One of the biggest changes was a switch from the S-Format syntax that marks lisp to an Algol like syntax most of you know from C, C++, Java, Perl, Python, Ruby and so on.

After hearing that podcast I had to try it but did not come far somehow.

I also told a friend of mine that I was checking out Dylan and he told me that I should try lisp. I did not care at that moment. Last friday I was curious and asked him to give me pointers about Lisp. I got a pretty big list where I should look and what I should get. The best pointer was Practical Common Lisp.

Practical Common Lisp is a book that is available free in the internet (you can also buy it as treeware). I installed sbcl and slime(do not wonder if the link to slime is not working, at the moment I am writing this the guys of common-lisp.net have some problems with their dns, but you can still reach the site using the ip 80.68.86.115 on my shiny new MacBookPro 17″ and started reading.

I tell you that book is amazing and lisp even more.

I can only encourage you to try it. REPL (Read Evaluate Print Loop) is the best thing ever. The integrated debugger interface, REPL and slime mode for emacs provided by the Slime package is beautiful!

It is really difficult to describe why. It just feels right and is mighty. Take a look by yourself and you will be shocked why Java, Perl or even Ruby are used so much. Lisp just rules and not only for scientific stuff.

I will write try to write something more in depth later.

VIM7 Fun

At work I have to use a pretty nasty Windows based development environment for a microcontroller.

You can configure it so that it starts a text editor of your liking to edit the source files. This editor gets called when you click on a file or on an error message in the compiler output. The DE also accepts a setting for parameters to the editor. There are two meta character codes. One is for the file (%F) and the second for the line the editor should jump to (%L). The problem is that it uses the same settings for the error invocation as for the normal file opening.

I wanted to use VIM7 and the new nice feature of tabs. As vim also supports remote invocation I decided that I want the DE to open the files in one central vim instance.

It took me some time to find out the correct command line setting so I want to share it with you.

gvim –servername <some_distinct_name> –remote-tab-silent +0%L %F

Now some explanations.

–servername is needed so that it always finds the correct vim window.

— remote-tab-silent is a directive that vim should start editing the file provided by %F in a remote window in a new tab if the file is not yet being edited. The “silent” addition makes vim not yield an error if there is no vim instance running yet, and start a new instance by itself.

The +0%L is there so that when %L is there vim jumps to that line but when %L is empty it does not jump to the end of file but to the beginning. That is why the 0 is there.

Ok I hope it is useful for someone. Have fun with VIM πŸ˜‰

Update: Corrected the unvisible some_distinct_name πŸ˜‰

VIM7 Released

Finally! After years of development a new major release of my and many others favorite text editor is there. It contains many new very nice and useful features:

  • Spell checking support for about 50 languages
  • Intelligent completion for C, HTML, Ruby, Python, PHP, etc.
  • Tab pages, each containing multiple windows
  • Undo branches: never accidentally lose text again
  • Vim script supports Lists and Dictionaries (similar to Python)
  • Vim script profiling
  • Improved Unicode support
  • Highlighting of cursor line, cursor column and matching braces
  • Translated manual pages support.
  • Internal grep; works on all platforms, searches compressed files
  • Browsing remote directories, zip and tar archives
  • Printing multi-byte text

Grab it here!

V for Vendetta

Hello everyone. It has been a very long time since I posted last time. My life was very hasty in the last time. But now I have something that I must share with all the people that want to take the time to read it.

I just saw the new filmy by the makers of Matrix. It was called “V for Vendetta”. I do not want to write a critique of the film. I only want to say that it is a must see and take the message of the film as a starting point for some reflections.

The main message for me was that if we do not take care we could end up in a state where “People are afraid of their governments.” We see many changes taking place that most of us do not see. Data retention, tracking, RFID… and so on.

The problem is that taking a side in the discussion if it is OK or not is also a problem already. If I say in my blog that I am on either side the internet will never forget that. And I may get in trouble in the future. So I will not take any side. At least not here. The reader should take a side by him/her self.

The biggest problem I see is that most of the People around us do not know about this changes. Most of them are not interested if the changes are made or not. Most of them say that it does not affect them. I think (and here I take a side) that it is a problem. I know that most people are not interested in politics. I can not say that I am a person that is politically active or really interested. I am in no party and I read news only as much as it is necessary to know if there are very heavy things happening. But one thing I know is that the changes our government is making are affecting us all and we all should open our eyes and think on which side we are. Not taking a side is the same as agreeing with the side that won. I took a side and will look for ways to express them in a way that will not get me in trouble in the future. I will be happy to hear any tips to how do that.

New Lens

Yesterday I decided to buy myself a new lens. It is the Nikon AF Nikkor 70-210 1:4-5.6. It was a used lens so it did not cost much. I hope at least that I did not pay too much for it. As far as I know such lenses do cost around 300Eur so 170Eur should be a fine price.

If you have other information or tips, tell me. I still have two weeks to give it back, if I am not happy with it.

I made some images with it. The last image in the photoblog is made with the new lens. I still have to learn how to use it. What setting it needs and so on.

You can see the lens here.

Exams once more

It is nearly half a year ago as I had my last exams. But it seems that I had them only some days ago. I did not really recover yet from the exams back then and now I have to write some more new ones. When will this end? My predictions are in one and half year. But who knows what happens in that time? Perhaps it will take even longer what I would really hate!!!

I hate that stuff as you can imagine.

My photography is suffering from all that. At least I try to finally work over the images taken in Warsaw this winter. But it needs it’s time. I can imagine though that when the exams are over I will not have one spare minute to do anything. Now … we will see.

Bloggies awards

Web log awards candidates have been announced. Many very interesting blogs have been nominated. It is very interesting to browse through the categories. Perhaps you find something interesting?

No I have not been nominated. I would probably die of the shock if my blog or photoblog would be nominated for that prestigious award.

Perhaps you also want to vote for some of the blogs listed there. But the most interesting thing is probably to have a list of very good blogs in different categories on one sight. I found some interesting ones for sure. πŸ˜‰