Welcome


... to my place on the web - a personal website where I keep articles, freeware programs and code snippets I've written, and a weblog where I share my ideas and insights on programming, technology, books, and life in general.

To browse the website, use the site map on the right-hand side of the screen. Below, you will find the ten most recent posts.

testing WP-Syntax

May 17th, 2008 at 8:50 am

I’ve installed the WP-Syntax plugin to add syntax highlighting and line numbers to code snippets I post, and this post is a test.

Here’s some C code without line numbers:

for (i = 0; i < 20; ++i)
{
    printf("i is %d\n", i);  /* print i */
}

Scheme code with line numbers:

1
2
3
4
(define (tagged? expr tag)
  (if (pair? expr)
    (eq? (car expr) tag)
    #f))

Python code:

1
2
3
4
5
6
7
8
9
def fib( ):
    """Unbounded generator for Fibonacci numbers"""
    x, y = 0, 1
    while True:
        yield x
        x, y = y, x + y
 
import itertools
print(list(itertools.islice(fib( ), 20)))

Perl code:

my %dict = (
  SENTENCE => ["NP VP"],
  NP       => ["ART NOUN"],
  VP       => ["VERB NP"],
  ART      => [qw/ the a /],
  NOUN     => [qw/ man ball woman table /],
  VERB     => [qw/ hit took saw liked /]
);
 
sub rand_production {
    my $items = $dict{+shift};
    return $items->[rand @$items];
}

Vanilla ‘pre’ tags, without WP-Syntax:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

D:\Documents and Settings\User>

The same, but with ‘lang=text’ using WP-Syntax:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
 
D:\\Documents and Settings\\User>

I wasn’t very happy with the default styles and colors used by the plugin, so I modified them to my taste, following the directions form GeSHi’s documentation (GeSHi is the syntax-highlighting package used by WP-Syntax).

The customization done by inserting the following code after the creation of the $geshi object in function wp_syntax_highlight of wp-syntax.php:

$geshi->set_keyword_group_style(1, 'color: blue; font-weight: bold;', false);
$geshi->set_keyword_group_style(2, 'color: blue;', false);
$geshi->set_keyword_group_style(3, 'color: black;', false);
$geshi->set_keyword_group_style(4, 'color: black;', false);
$geshi->set_strings_style('color: maroon;', false);
$geshi->set_escape_characters_style('color: maroon;', false);
$geshi->set_symbols_style('color: black;', false);
$geshi->set_numbers_style('color: black;', false);
$geshi->set_methods_style('color: black;', false);
$geshi->set_regexps_style('color: maroon;', false);
$geshi->set_comments_style(1, 'color: darkgreen;');
$geshi->set_comments_style('MULTI', 'color: darkgreen;');

I have also followed the WP-Syntax instructions to place wp-syntax.css in my theme directory to override my default styles for the ‘pre’ tag.

Book review: “My Michael” by Amos Oz

May 16th, 2008 at 5:22 pm

(read in Hebrew)

This book was written 40 years ago and is set in Jerusalem of the 1950s. I liked the description of Jerusalem and of life in Israel at that time, and I liked the writing style in general (there’s something delightfully old-style in it). What I didn’t like was the main characters. Most of all I hated Hannah. She’s a terrible human being. Terrible to herself, but mostly for others - who have to bear the relationship with her.

I think the idea for such a character isn’t a new one, as Hannah reminded me a lot of the main character in Flaubert’s “Madame Bovary” (I hated that one as well, as you can guess). Why didn’t I like her ? Many reasons: negativity, irrationality, inconsideration. In reviews I read that many people identified with the character. I feel sorry for these people, I truly do.

And I didn’t like Michael either. He’s a bit better though, since it seems that he leads the life he wanted to lead and is relatively happy about it. Not that it’s an excuse to be in a relationship like that.

Ooh… that was a negative review, wasn’t it. I don’t want to create a wrong impression - although I disliked the book, I wouldn’t say it’s terrible or something like that. It’s very readable, and I actually enjoyed parts of it. It’s the main character who got to me. There’s simply a fundamental conflict between her and my view of life, and I couldn’t get over it while reading the book. And the most annoying part is that the book and its reviews in some sense seem to be glorifying Hannah, rather than criticizing her - and I just don’t understand why.

Python

May 14th, 2008 at 6:36 pm

As I wrote extensively earlier, I’m not fully satisfied with either Perl or Ruby for my main programming language of choice. I always knew there is the third option, Python, but for some reason never paid any serious attention to it.

Well, this is about to change - I’ve decided to give Python a try. What gave me the push was two things:

  • I was playing with wxWidgets earlier this week - it’s a really nice cross-platform GUI framework. I’ve used the Perl binding - wxPerl, for a toy project in the past but wasn’t entirely happy with it (with wxPerl, not wxWidgets). Well, while reading the new wxWidgets docs I saw wxPython mentioned as the best binding around, and some web browsing confirmed it. So, Python may be just what I was looking for in terms of a good native-widget GUI framework binding to a high-level language.
  • A few days ago I’ve read a blog post about Sage - a mathematics software suite based on Python that provides an alternative to Matlab. Python has a lot of scientific computing packages, like SciPy and NumPy, and Sage seems to be a clever aggregate of Python with these and numerous other modules suitable for number crunching and plotting. This looks very interesting.

So, I’ve installed the ActivePython distribution on my Windows computer and already read a few chapters of Dive into Python. It’s too early to form impressions - but I will definitely have more to say on the subject during the next few days.

Book review: “The Last Templar” by Raymond Khoury

May 13th, 2008 at 7:17 pm

I had a few hours to kill in the airport at Lima on our way back from Peru, so I walked into the airport book store. All the stores at airports are very expensive, including book stores, but they are a very good way to pass some time. Unfortunately, these stores don’t have many quality books and are stocked mostly with time-fillers like thrillers and mystery page-turning books (by Grisham, King, Coben, Baldacci, Brown and co) This kind of makes sense, I guess, because this was exactly the type of book I was looking for.

“The Last Templar” was one of several (I counted about 4) books which boasted something about “The Da Vinci Code” on their back covers. It seems to be a common theme lately - whip up a quick plot with many unexpected twists, pepper it with some of the many mysteries early Christianity has to offer, and you have a book.

The book itself was everything I expected it to be. A very fast-moving plot, completely shallow characters, lots of “exciting surprises”, a love story, and some interesting historic tales. I can’t say I liked it, but I can’t say I hated it either. The best would be to say that it served its purpose - and helped me pass the time in the airports and on flights back home.

It’s difficult to refrain from a comparison with Da Vinci Code. I found The Last Templar to be better at least in once sense - it had far fewer twists, and the plot was more linear and logical. On the other hand, some of the twists it had weren’t very reasonable or believable - especially in the end, it appeared as if the author really wanted a certain ending and brutally bended the plot to eventually reach it.

And by the way, the theological discussion that took part in the last part of the book was actually quite interesting - perhaps I found it to be so because it was close to my own feelings on the subject.

Israel’s contributions to information technology

May 10th, 2008 at 6:48 pm

There’s an interesting article here (ynet.co.il, Hebrew) about the subject. Here’s a headline-level translation (the article itself gets deeper on each point):

  • The ZIP compression method (used in ZIP compression, 7z, GIF, PDF and other formats): based on the LZ algorithm by two Israeli researchers: Abraham Lempel and Yaakov Ziv
  • The first VoIP application was developed by an Israeli company (VocalTec) in 1994. It was named… iPhone. The company didn’t succeed to lift, but many others benefited from its technological breakthroughs.
  • Disk On Key - the small USB-flash storage drive, was invented by M-Systems, an Israeli company founded by Dov Moran. M-Systems was purchased by Sandisk (also an Israeli company, by the way)
  • Babylon - translate in a click. The pioneer of this technology, in 1997.
  • PHP - the popular server-side programming language was developed by two Israelis.
  • ICQ - the first of the hyper-popular instant-messaging application, was developed by Mirabilis, an Israeli start-up which was later purchased by AOL.
  • MetaCafe - a popular video-sharing website website that was developed by an Israeli in 2003, long before YouTube.
  • Haifa’s Intel development center, has large parts in the development of MMX, Pentium 2, and lately the huge success of the Centrino mobile platform. The Haifa center is currently Intel’s main CPU development house, and most of the currently popular chips (including Core 2) were designed there.
  • The term FireWall was coined by an Israeli internet security company - the giant CheckPoint, with their corporate security solution in 1994. Home users are probably more familiar with its ZoneAlarm product.
  • The RSA encryption algorithm, which is used almost universally for public-key encryption these days is one-third Israeli, the ‘S’ coming from the surname of Adi Shamir, an Israeli cryptography researcher.
  • Israeli companies have strong contributions to early anti-virus technology. In fact, one of the earliest anti-virus products (in 1988!) was made by the Israeli company BRM, which was purchased by Symantec.

I skipped one or two that didn’t seem important enough. If you have some other things in mind, let me know and I will update the list.

SICP - conclusion

April 18th, 2008 at 4:54 pm

I’ve completed the SICP reading project, which I began on June 19th, 2007. In hindsight, it seems like a very long time (almost a year!), during which this was my main hacking project at home. So, in this conclusion I want to examine my progress, and compare the result with my initial goals.

The original plan was:

  1. Read the book
  2. See all the video lectures by Sussman and Abelson themselves
  3. Do most of the interesting exercises in the book
  4. Do some of the larger projects listed here and here

Let’s see how I’ve managed:

  1. Done
  2. Done
  3. This is the point I’m most happy with. I’ve completed the vast majority of the exercises in SICP and posted them online. Of the 356 exercises in the book, I’ve skipped about 20, so I’ve completed 94% of the exercises – which is far above my initial plans.
  4. I didn’t do this, but there’s no need, having completed so many of the exercises. I feel I gained a completely solid understanding of the material, and won’t gain much by doing the projects.

Also, I originally planned to reimplement all the code do all the exercises in Common Lisp. Later I changed my mind and decided to use PLT Scheme for some of them. Eventually, I’ve been using both languages interchangeably, which is a good thing, as I got some practice with both.

Here are some numerical statistics that emphasize the magnitude of this endeavor:

  1. I’ve written 52 blog posts (not including this one) in the SICP category, spread over 10 months.
  2. The combined total length of my posts (including code snippets) is 66,265 words. For comparison, Jack London’s “Son of the Wolf” is 50K words long.
  3. Some of the large projects from the book I’ve re-implemented in wholeness: a constraint propagation solver, an evaluator (interpreter) for Scheme, a generic object-oriented arithmetic package including complex and polynomial arithmetic, Huffman encoding, an interpreter for a logic programming language similar to Prolog (as a DSL on top of Lisp), a picture-language interpreter, a simulator for digital circuits, a symbolic differentiation package, a virtual machine for a simplified pseudo-assembly DSL, an interpreter for Scheme written in this pseudo-assembly, and finally, a compiler for Scheme that spits out pseudo-assembly code.
  4. Counting with the cloc tool (Count Lines Of Code), the total physical LOC count1 for the code I’ve written during this time: 7,300 LOC of Common Lisp, 4,100 LOC of Scheme. If you prefer raw LOCs2, it’s 10,800 LOC of Common Lisp, 5,600 LOC of Scheme. So this is more than 10 KLOC of Lisp code, any way you look at it, which is a lot, since Lisp is a very expressive high-level functional language.

A word on SICP and its exercises. Abelson and Sussman have created a masterpiece, a book initially written in the 1980s, and that still hasn’t lost one bit of relevance. Everything it contains must, must be learned and understood by any aspiring programmer. It teaches algorithms and data structures, good programming style, provides some contact with large systems, experimenting with their implementation and modification. You will learn about functional programming, imperative programming, object-oriented programming in it. You will learn how to implement interpreters, compilers, arithmetic systems, simulators, a whole virtual machine in it, and much more.

The exercises of SICP are essential to understanding. Looking back at the work I’ve done on the book, I don’t think I would have understood it near so well without doing a lot of the exercises. There’s only so much material that can be gained from reading. Getting your hands dirty with code is essential to true understanding. And the authors of SICP brought this concept to perfection, with their excellent exercises, that are an unreplaceable companion to the book. Although they’re not 100% perfect, for the most part the exercises are very well thought out and tuned to aid understanding and practice writing parts of large systems.

1 Physical LOC: lines of code, excluding comments and blank lines. To test my Common Lisp and Scheme code counts with cloc.pl, I used these commands:

cloc.pl --force-lang="Lisp",lisp *.lisp
cloc.pl --force-lang="Lisp",scm *.scm

2 Including comments and blank lines, as output by wc -l.

SICP section 5.5

April 18th, 2008 at 12:17 pm

It took me some effort to get the compiler code to work in conjunction with the explicit control evaluator, especially when it came to linking compiled and interpreted code. The prime problem was additions I’ve made to the register machine simulator in previous chapters, in answer to exercises, and that didn’t work well with the needs of the compiler.

For example, in one of the exercises it was requested to test whether operations are being done on labels, and flag these cases as errors. However, in compile-lambda, the compiler creates this assignment:

`((assign ,target
    (op make-compiled-procedure)
    (label ,proc-entry)
    (reg env)))))

Read the rest of this entry »

Book review: “Alexander the great” by Peter Abbott

April 9th, 2008 at 9:01 pm

(Audio book)

This book is from a “lighweight history” series by Peter Abbott. As the name suggests, it deals with the history of Alexander Macedon, a.k.a. Alexander the Great, the Greek king of circa 300 BC who managed to conquer most of the then-known world.

It’s well written and narrated, and is very entertaining to read. The author strikes a very good balance between historical comprehensiveness and accessibility for the layman reader. The latter is very important, and is often omitted in historical books, making them barely readable.

One story from the book that particularly impressed me was the siege of Tyre. The city resides on an island a couple of miles from the shore, and to conquer it Alexander has ordered his army to build a causeway to connect to it from the shore, after a siege of several months. The Tyrians replied by attacking the soldiers who were building the causeway from ships. The Greeks built wooden walls along it to protect themselves from arrows and spears. In response, the Tyrians ignited the wall by sending a “kamikaze ship” on it, loading it with tar and setting it on fire. Later, a storm ruined the causeway almost completely. Alexander did not despair, however, and ordered his troops to rebuild the path, this time covering the wooden wall with fresh hides to prevent ignition, and hired ships that fought with Tyrian ships and didn’t allow them to attack the builders. At last, the city has been conquered. This description of the battle was as readable as a good novel, and the accounts of military ingenuity from both sides are striking.

Peru

April 7th, 2008 at 7:58 pm

Two weeks from now, we are going to be somewhere above the Atlantic, on a Iberia flight from Madrid to Lima, Peru.

Peru flag

It’s a 20-day vacation we’ve been planning for some time now. Peru is a rather large country, and it’s impossible to see all of it in such a short time, but we hope to visit most of the highlights.

Peru map

The most illustrious spot to visit in Peru is, of course, the Machu Pichu, “The lost city of the Incas”.

Machu Pichu

Machu Pichu has recently been elected as one of the new seven wonders of the world, and is considered to be the prime attraction in South America. We’ll reach it by partaking the Inca Trail- a four day trek. 43 kilometers of mountains, Inca ruins and jungle reaching as high as 4,200 meters.

Peru has many other interesting places. We haven’t planned the trip to the last detail yet, and probably won’t do it until we actually reach Peru. Periodical reports will be posted, as always, to the travel log.