November 25, 2007

Getting Started with Scheme on Ubuntu — Part 2

Filed under: Linux,Scheme — bnsmith @ 11:59 pm

Installing and Using SLIB

Scheme is a very minimalistic language. This is Scheme’s great strength, but this trait can also make the language seem a little bit barren. There is a collection of excellent libraries that can help allieviate this, though using them requires some set-up. First, follow the directions from Part 1, if you haven’t already. As with Gambit Scheme itself, the version of SLIB in the Ubuntu repositories is not the latest, so we will install from source.

Go to the SLIB website and download to your home directory. The download link is under the “Quick Start” heading.

Next, open a terminal (Applications -> Accessories -> Terminal) and enter the following commands:

cd slib
sudo make install

Then, edit the SLIB configuration file with the command:

sudo gedit /usr/local/lib/slib/gambit.init

Find the line:

  ((unix)    (lambda () "/usr/local/share/gambc/"))


and change it to:

  ((unix)    (lambda () "/usr/local/Gambit-C/current/"))


Now start the interactive interpreter with root permissions:

sudo gsi -:s /usr/local/lib/slib/gambit.init -

In the interpreter, enter the command:

(require 'new-catalog)

Exit the interpreter by pressing CTRL-D twice. Finally, copy and paste this command into your terminal:

echo "(include \"/usr/local/lib/slib/gambit.init\")" > ~/.gambcini

SLIB is now fully installed and can be used by the Gambit Scheme interpreter. To test the installation, run the interpreter by typing gsi and paste in the following code:

(require 'random)
(random 10)

This should display a random number from zero to nine. It is similarly possible to use SLIB with programs saved in files. Copy the following code into a text file named slibtest.scm:

(require 'printf)
(require 'srfi-1)
(define userlist '((45607 "Ted Randalph" 34.90 5)
                   (91238 "Rob Smith" 32.45 3)))
  (lambda (userinfo)
    (printf "Employee %s (%d) has %d years experience and makes $%.2f per hour.\n"
      (second userinfo) (first userinfo) (fourth userinfo) (third userinfo))) userlist)

This program can be run by entering gsi slibtest.scm and should display the following output:
Check out the SLIB documentation for a complete list of what is available.


November 23, 2007

Getting Started with Scheme on Ubuntu — Part 1

Filed under: Linux,Scheme — bnsmith @ 3:44 am

Installing Gambit Scheme

As I described in my previous post, I am a fan of the Gambit implementation of Scheme. While following these instructions, try to keep in mind that the Scheme community is smaller than the communities of the more major languages like Python or Ruby, so there are still rough edges that get in the way. I hope that my experiences can speed things up for other fledgling Schemers.

It is possible to install Gambit Scheme from the Ubuntu repositories. However, the repositories contain an older version, so I recommend building Gambit Scheme from source instead. First, go to the Gambit Scheme website.


Click on the “Sources” link and save the gambc-v4_1_0.tgz file to your home directory. Next, open up a terminal (Applications -> Accessories -> Terminal), and enter these commands:

tar -xzvf gambc-v4_1_0.tgz
cd gambc-v4_1_0
./configure && make
make check
sudo make install
sudo make bootstrap
cd /usr/bin
sudo ln -s /usr/local/Gambit-C/current/bin/gsi gsi
cd ~

Once the installation is complete, conduct a few tests. From your terminal, enter the command:


You should then see Gambit’s interactive interpreter prompt. Enter the following code:

(define numlist '(2 10 6))
(map (lambda (x) (* x x)) numlist)

You should receive these results:


Exit the interpreter, by pressing CTRL-D twice. You can also use the Gambit Scheme interpreter to run Scheme programs stored in files. As an example, put the following text into a file named hello.scm:

(display "Hello World!\n")

Run the file with the command:

gsi hello.scm

That should be enough to start experimenting with Scheme. Part 2 will describe the installation and use of the SLIB libraries.

November 17, 2007

On the Importance of Programming Language Popularity

Filed under: Scheme — bnsmith @ 6:20 pm

I recently decided to learn Scheme. I’ve only just begun this journey, but already I’ve learned a great deal, some of which has nothing to do with Scheme programming.

My first step in learning Scheme was to choose an implementation. I knew that there were numerous Scheme implementations to choose from, as one would expect, given how easy it is to implement the language. This was, in fact, one of the things that drew me to the language in the first place. I was still just starting to learn Scheme, so I figured that it wouldn’t really matter which implementation I selected. As long as I was just playing around and not implementing real software, I could always switch later with relative ease.

So I installed MIT Scheme, fired up the interpreter and started typing in my first tentative lines of code:


It worked! I had successfully calculated that seven times two is fourteen! I was clearly well on my way to becoming an omnipotent programmer deity. Now, how about changing that first line to use the number 13 instead of 3? I tapped the up-arrow key on my keyboard and:


Well, apparently the MIT Scheme interpreter doesn’t support that. This discovery gave me pause. I really like learning with an interactive interpreter, and not having the ability to bring back the previous line would make things much more difficult. No worries though; there are plenty of other Scheme implementations out there. There has to be at least one that does what I want. Chicken Scheme seemed pretty popular. Trying the same code again:


And the up-arrow:


Chicken Scheme’s interpreter has the same problem. I also tried MZScheme, Scheme48 and Guile, with the exact same result. Five Scheme implementations, and they all suffer from this same issue.

And then it hit me. This is the sort of thing that causes newbies like me to give up and move on to something else. In fact, I think that I may have actually done just that after a previous attempt at learning Scheme, months ago.

Well, I didn’t give up this time, and I eventually found a Scheme implementation that supports my beloved arrow keys in its interpreter. And the winner is: Gambit Scheme. This excellent implementation seems to have been influenced by the “batteries included” philosophy that I love about Python. And given the state of the programming language world right now, I don’t think that “batteries included” is optional anymore. For a language to win users, and all of the benefits that a large community brings, at some point someone must create a polished implementation without the rough edges that I had to wrestle with. To some degree, this is a chicken and egg problem. On one hand, you must deal with all of the boring little details to grab users and build a big community. On the other hand, a big community will mean more contributors willing to tackle the boring details. I suppose that the polish of the implementation and the size of the community must move in lock-step. The only thing that anyone can do to speed this process is to adhere to the “batteries included” philosophy and encourage others to do the same.

If you’re thinking about learning Scheme, I highly recommend that you give Gambit a try. My next posting will explain how to install Gambit and set up the SLIB libraries on Ubuntu 7.10.

November 1, 2007

Practical Applications of Searle’s Chinese Room

Filed under: Programming Professionally — bnsmith @ 2:18 am

Consider the following:

A paper with Chinese characters is passed into a closed room through a slot on the door. The room’s occupant picks up the paper and examines it briefly, but he can’t read Chinese characters, and so he shrugs and sets about his task. He brings the paper over to his desk and opens a hefty volume containing thousands of rules describing a complex procedure. The rules themselves are written in English, but they are extremely tedious and dry, and so the man feels no enthusiasm for the dull task that he now begins to execute. The book tells him to look at first character, painstakingly copy a few of the inscrutable Chinese characters onto a new piece of paper, and then proceed to follow the rule on page three-thousand, four-hundred and ninety-eight. The rules are extremely detailed, providing a course of action for any possible set of characters. After several hours, the instructions tell the man that his task is complete, and that he should now take his new sheet of paper and pass it back out through the slot in the door.

A native Chinese speaker then retrieves the resulting sheet of paper and reads it, likely with some surprise, for the sheet of paper contains a coherent response to the letter that she had written and slipped into the slot earlier in the day. The volume of rules is a remarkable piece of work, indeed. It describes a completely mechanical process by which any suitably meticulous person can appear to understand the Chinese language.

The situation that I have just described is a thought experiment known as “Searle’s Chinese Room.” The philosopher who originally described these events used it to show that even if a computer seemed to understand Chinese (or English, French, Spanish or any other human language), it wouldn’t neccessarily mean that the computer was sentient, as you and I are.

Of course, this is all common knowledge for most computer programmers. However, you may not have realized that a variation on Searle’s Chinese Room has been adopted by many large software companies.

The “Large Software Company Room” method begins when a software team-lead passes a piece of paper through a slot in the door and into the sealed room. The piece of paper contains a list of character strings, mostly made up of English letters, but with the odd number thrown in as well. For example, character strings such as WTL, DB2 or UDP sometimes appear on these lists. The occupant of the room examines each string on the list, and compares it to the character strings on a stack of other documents. If he finds that one of the other documents contains one or more of the character strings on the list, he places that document into a separate pile. Once he has finished sorting the documents, he takes the pile of documents that contained at least one of the desired strings and passes the pile back out through the slot in the door. The software team-lead outside of the room may then select one of the resulting documents, called “Resumes,” and contact the person who wrote it. What I have described as the “Large Software Company Room” is more commonly referred to as the “Human Resources Department.” In practice, the list of desired strings will frequently also contain other qualifiers, such as the number of years of experience in using a particular character string.

Sometimes this system can have undesired consequences. If a software team-lead asks for “Resumes” containing “Java,” then all resumes that don’t contain “Java” but do contain strings like “J2EE” and “JDBC” will be discarded. The obvious advice would be for the software team-lead to simply be sure to include all character strings that could possibly indicate a desirable candidate. However, I doubt that this is really a workable strategy. For example, even if I’m looking for a Python developer, that doesn’t mean that I would automatically eliminate a candidate with no Python experience. If they had experience with Scheme, Erlang, Haskell, Ruby, Smalltalk, Perl or any number of other interesting tools and technologies that have piqued my interest, then I might decide to invite that person to an interview. The only way to really know for sure is to see the Resume myself.

I understand that this may not always be possible if a company receives ten thousand resumes for a single opening, but how often does that really happen? I don’t object to HR departments helping to take some of the burden of hiring away from technical people, but the help should always be optional rather than being forced on resentful software developers by arbitrary corporate policies.

Create a free website or blog at