Tuesday, October 24, 2006

Tutorial: Scripting a symbol search engine - Getting started

This is the first in a series of posts that will guide you through the implementation of a simple-minded search engine for Scheme symbols using the SchemeScript plug-in for Eclipse.

The main focus will not be on the search engine itself, but rather on all the SchemeScript features that make it a nice platform for Scheme programming, covering some of the not so well documented features. (SchemeScript comes with some documentation, of course, but you are as busy as I am... you never read it, do you?)

And be warned! The goal of this tutorial is not to show good programming habits in Scheme, but to show how SchemeScript can be used to program quick hacks, to prototype some simple ideas interactively.

Now let's see what we will try to accomplish in this tutorial.

The Problem

The problem consists in finding all Scheme source files in the Eclipse workspace that contain at least one of list of specified symbols, sorting them by the number of occurrences (the files with the most occurrences first), and presenting them to the user.

SchemeScript already indexes all symbol references. When Eclipse is started, all Scheme source files are scanned and each time a Scheme source file is saved, it is scanned again. All references are kept in a symbol references table. (There is room to optimization here, but this will be the subject of another article.)

So much of the task will be to create a front-end to this table.

Why Kawa?

I know, this is a controversial one. I've been asked numerous times. I could use a more R5RS-compliant implementation, like SISC. So why choose Kawa?

The answer is very simple: subclassing! In Kawa, you can subclass Java classes, in SISC you can't. That's it. And subclassing is something you do a lot when developing on the Eclipse platform.

Getting started

Before we proceed with the code itself, we need to set up the environment. So do the following:

  • Start Eclipse.
  • Switch to the Scheme perspective. This is the only way to start the interpreter.
  • Select the Scheme/Select interpreter/Embedded Kawa menu item:

  • Start the interpreter console by pressing F9 (Note: I will use the default key bindings. These bindings may not work on all platforms, though. But you can change the key bindings in the Eclipse Preferences.)


We are now ready to start coding. We must first create a new Scheme source file in one of our projects. We will name it search.scm. Once done, we insert a file header comment by pressing Alt-C, H. You should see something like:


To make sure the interpreter is properly running, type the following code in the editor:
(begin
(display "That works!")
(newline))

move the cursor past the last closing parenthesis, and press Ctrl-Enter You should now see something like the following in the console view:


That's it for today. Next time, we will see how to use the Kawa Scratchpad view to create and test SWT components in Scheme.

Categories: SchemeScript, Eclipse, scripting.

1 comments:

Marco said...

Thanks for that introduction into SchemeScript. I will look forward to the next episode.