| How to extend C programs with Guile | ||
|---|---|---|
| <<< Previous | Next >>> | |
Guile is an interpreter for the Scheme programming language. It reads in Scheme files and executes the instructions contained therein. In this way, it is just like many other scripting languages out there in the wild, such as Perl, BASIC, or Korn Shell. Guile is just one of many implementations of Scheme for the PC.
What elevates Guile above the pack of Scheme interpreters is its embeddability. It is most special not in what it is, but in how it is packaged. The Guile interpreter can be contained in a library, libguile, that can be linked to a C program. A C program that links to the Guile library can then use code written in Scheme as well.
Having a C program that can read Scheme can be useful. When a C program linked to libguile has some of its functionality written in Scheme, the Scheme code can be modified without recompiling and reinstalling the executable, creating a more hackable product.
Flipping through the reference manual is daunting. Within a few pages, one learns that there are many ways to use Guile, and many ways that Guile and C can interact. One might find it difficult to know where to begin.
This book attempts to be a gentle introduction to Guile and to focus on how to use it specifically as an extension language. It does not encompass the many ways to use Guile. It will not discuss how to write stand-alone Scheme scripts with Guile, or how to extend or hack Guile itself. It will focus only on using Guile as helper functionality for C programs. Hopefully it will explain this one method fairly well.
The Guile story begins with Lisp, a language that grew up as the internal computer language of the M.I.T. Artificial Intelligence Project in 1958. The structure of Lisp programs was intended to be logical and have a level of "mathematical neatness" that was absent in the more pragmatic languages of the day, like Fortran or Algol. [1]
Lisp became a fairly common language for university research because of a commercial implementation by the Digital Equipment Corporation for its PDP-10. Even so, it was a language that lacked cohesion among its developer community. Unlike other languages that began the business of standardization fairly early on, there was no formal Lisp standard in the 1960s and 1970s.
Scheme is a product of those unstandardized days. It is a dialect of Lisp in which the creators were trying ensure a type of purity in the way procedures were defined and implemented. Scheme began to be used in language courses at MIT, Yale, and Indiana University.
As Scheme became more widespread, it, too, began to separate into different dialects. A standardization effort was launched in 1984, which led to the first Scheme specification. This specification is now in its fifth revision: The Revised(5) Report on the Algorithmic Language Scheme, or R5RS for short. The R5RS was complete in 1992.
The history of the Guile interpreter dates to 1994 in which there was an online discussion now called "The TCL War." TCL is a scripting language that is embeddable for use as a simple extension language. It was well suited for that purpose. As its popularity increased, there came questions about its use in the software that formed the GNU project. The director of the GNU project, Richard Stallman, felt that embedded languages should not be overly simple. They should be full-featured languages in their own right. He came to this conclusion after having developed the text editor EMACS, a C program with a Lisp extension language in which a powerful extension language was very useful. [2]
A project was launched to make an extension language for the GNU project. By modifying an existing Scheme interpreter, developers were able to quickly create an embeddable Scheme library, named Guile, in 1995.
Guile is an free implementation of Scheme. It is free as in freedom. The user is free to download the sourcecode and modify it as he chooses. He or she is free to store it in any manner, sell it, or even give it away. Becuase people in collaborative software projects are giving people, GUILE is also free as in ``free beer.'' While it is perfectly legal for a free software project to charge for distribution of software, there are many web sites willing to offer it as a free download.
Guile is part of the GNU project. If you find Guile to be useful, consider donating money to the GNU project to help its development to continue.
| [1] | see McCarty, John. ``History of Lisp'' Stanford University, 1979. http://www-formal.stanford.edu/jmc/history/lisp/lisp.html |
| [2] | These days, TCL has become a powerful and complete programming language in its own right. For those readers that become excited about the concept of an extension language, but can't deal with Guile's Lisp-like syntax, TCL may be useful. |
| <<< Previous | Home | Next >>> |
| How to extend C programs with Guile | The State of Guile |