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 slib3a5.zip 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:
unzip slib3a5.zip 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:
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))) (for-each (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.