Superl

May 23rd, 2009

Superl is a project I developed several years ago. It was inspired by a great program I was working with that went by the same name.

Superl is a graphical Perl interpreter written in Perl. It opens one simple window in which you can type in your Perl commands and it will execute these commands for you. Superl also has some nifty features like:

  • Scrolling through the history of commands you’ve entered.
  • The _ function gets the result of the previous command (like ‘_’ in python).
  • Function/Variable completion with ctrl+space.
  • The result of each command is shown in the output window in blue.
  • Prints to STDOUT from your program will be shown in the output window in green.
  • Prints to STDERR from your program will be shown in the output window in red.

Superl runs on both Windows and Unix/Linux. All it needs is Perl and the Perl Tk package.

Superl is extremely useful for performing quick tasks with Perl or for checking out small pieces of code. Superl isn’t meant to be used as a Perl IDE. It doesn’t have any form of file management. It’s meant to be a graphical Perl interpreter.

I’ve registered Superl under Sourceforge as an open source project. It is distributed under a GPL license.

The Sourceforge project homepage is here. On it you can find more details about the project and you can download the project files.

The Game of Evolution

May 16th, 2009

I’ve recently added a new page to my website – The Game of Evolution.

This game is an advanced version of the famous Game of Life.  Similar to the Game of Life, the Game of Evolution is a zero player game. The game starts with an initial configuration and the user can watch how the game advances.

In this game animals must survive in a world according to a set of rules. Each animal starts with an initial amount of energy, and loses energy each turn when it performs actions like moving or reproducing. An animal can gain energy by performing actions like sleeping or eating. The animals make their decision as to which action to perform each turn according to their genome. Each animal has its own genome that is transferred to its offspring with a random mutation. The winner of the game is the animal which outlives all the other animals.

It is interesting to study which genomes are more likely to survive in the world, and how small parameters like the length of the genome, the amount of energy spent and gained by different actions and the initial placement of the animals affect the outcome of the game.

The game is located here.

More information on the game rules is located here.

The game is currently in a fairly initial state, so many more features are expected to be released in the future.

I’d be more than happy to hear any comments/ideas you may have. Email me at yuval (dot) baror [dot] website {at} gmail (dot) com

Improved SWIG C# wrappers std_vector.i and std_map.i – part 2

May 9th, 2009

* Note: since posting this a new version of SWIG has been released (version 1.3.40). This version includes the improved C# wrappers discussed here. A simple explanation about these wrappers can be found here.

After posting my previous post on the improved SWIG C# wrappers for std::vector (std_vector.i) and std::map (std_map.i) I was contacted by one of the main developers of SWIG, William Fulton. This led me to discover the extensive testing suite that SWIG is delivered with.

I tested my improved std_vector.i wrapper against the testing suite, and this went well. Then I wanted to test my std_map.i wrapper, as it is a complete rewrite of the existing wrapper.  Since there was no existing test suite for the std_map.i wrapper, I created my own test suite for this wrapper. This flushed out a lot of bugs, and the wrapper is hopefully in much better shape now.

Here is the new version of std_vector.i wrapper: std_vector.i

And the new version of the std_map.i wrapper: std_map.i

The two files relevant for the testing suite of std_map.i are: li_std_map.i and li_std_map_runme.cs

These can be incorporated in the existing SWIG testing suite. I tested them on Windows using Visual Studio. I’m also attaching my C++ and C# solutions for this testing suite. To use them – first rebuild the C++ solution, and then rebuild the C# solution and run it. std_map_test.zip

These wrappers will now hopefully be included in the next release of SWIG, though a good code review wouldn’t hurt…

Improved SWIG C# wrappers for std::vector and std::map

April 28th, 2009

I recently ran into the very impressing SWIG package. This package takes functions and classes written in C++ and creates wrappers for them in several languages including Perl, PHP, Python, Java, C#, Ruby and many more.

Using this package is quite easy. It comes with several examples for each language which you can just change a bit to fit your specific needs.

I used this package to wrap some C++ code I had into C# and was quite pleased with it. I started running into problems when I wanted to use STL containers like std::vector and std::map and have them translated into C# generic containers like IList and IDictionary. The C# wrappers supplied with SWIG for these types didn’t implement the relevant interfaces. The std::map wrapper was actually quite useless because it supplied only very basic functionality without even supplying a method for receiving the existing keys in the map.

So I decided to enhance the existing wrappers and have the std_vector.i wrapper implement the IList interface and have the std_map.i wrapper implement the IDictionary interface. I have attached my version of the wrappers here. If you have any comments or suggestions – please post them.

The improved std::vector wrapper: std_vector.i

The improved std::map wrapper: std_map.i

* Note: an updated version of these wrappers is available in my next post on this subject: Improved SWIG C# wrappers std_vector.i and std_map.i – part 2

Fermi’s Commute to Work

April 4th, 2009

How much does the commute to work cost? All of us spend time on the road each day on the way to work and back. Have you ever stopped to think how much this costs? I’m not talking about how much this costs the employees, but how much this costs the country’s economy.

I tried to approximate this using the following method:

1) I assumed that on average each person spends 20 minutes per day on the way to work and another 20 minutes on the way back home.

2) I assumed that if each person saved this time and made it instantly from home to work and back, 50% of the saved time would be spent doing additional work.

3) The GDP of Israel (in 2008) was 760 billion shekels.

Using these figures, we can conclude that if people did not have to commute and instead spent 50% of the saved time at work, the GDP would grow by 3.7% or 28 billion shekels. In fact, saving an average of one minute per person on their commute would increase the GDP by 700 million shekels.

Considering that the government gets a fat slice of the profits of each company, this should be quite an incentive to try to cut back on commute time. Be that cutting back on traffic jams, or trying to develop new roads, or better yet creating a decent public transportation system.

Hello world!

March 28th, 2009

The next natural step to building your own website is setting up a blog. So here I am. This first entry will be short and to the point. Just saying “Hello”. The next entries will hopefully be more interesting.