How to Run Scheme Programs from the Command Line

Since I started playing around with Lisp (Scheme dialect initially) I have been trying to find the simplest way possible to run my programs directly from the command line. MIT-Scheme allows you to load files with Scheme code, but you need to run it from inside the program, so not very practical. I also tried Chicken Scheme, but found it cumbersome.

Today I finally found a simple solution. First of all you need to install Guile, which is a Scheme interpreter (among other things). You can install it on your Linux machine with this:

sudo apt-get install guile-2.0

After that you just need to create your Scheme program with your favorite text editor, and add a instruction on top of it to use the Guile interpreter. For instance, here’s a Hello World example:

<code>#!/usr/bin/guile -s

(display "Hello World!")

Finally, make that file executable with chmod +x. For instance, if you named the file test.scm, use this command “chmod +x test.scm”. Now you can run it with ./test.scm.

Leave a Reply

Your email address will not be published. Required fields are marked *