Festival's Scheme Programming Language

This chapter acts as a reference guide for the particular dialect of the Scheme programming language used in the Festival Speech Synthesis systems. The Scheme programming language is a dialect of Lisp designed to be more consistent. It was chosen for the basic scripting language in Festival because:

Having a scripting language in Festival is actually one of the fundamental properties that makes Festival a useful system. The fact that new voices and languages in many cases can be added without changing the underlying C++ code makes the system mouch more powerful and accessible than a more monolithic system that requires recompilation for any parameter changes. As there is sometimes confusion we should make it clear that Festival contains its own Scheme interpreter as part of the system. Festival can be view as a Scheme interpreter that has had basic addition to its function to include modules that can do speech synthesis, no external Scheme interperter is required to use Festival.

The actual interpreter used in Festival is based on George Carret's SIOD, "Scheme in one Defun". But this has been substantially enhanced from its small elegant beginnings into something that might be better called "Scheme in one directory". Although there is a standard for Scheme the version in Festival does not fully follow it, for both good and bad reasons. Thus finding in order for people to be able to program in Festival's Scheme we provide this chapter to list the core type, functions, etc and some examples. We do not pretend to be teaching programming here but as we know many people who are interested in building voices are not primarily programmers, some guidance on the language and its usage will make the simple programming that is required in building voices, more accessible.

For reference the Scheme Revised Revised Revised report describes the standard definition [srrrr90]. For a good introduction to programming in general that happens to use Scheme as its example language we recommend [abelson85]. Also for those who are unfamiliar with the use of Lisp-like scripting languages we recommend a close look as GNU Emacs which uses Lisp as its underlying scripting language, knowledge of the internals of Emacs did to some extent influence the scripting language design of Festival.

Overview

"Lots of brackets" is what comes to most people's minds when considering Lisp and its various derivatives such as Scheme. At the start this can seem daunting and it is true that parenthesis errors can cuase problems. But with an editor that does proper bracket matching, brackets can actually be helpful in code structure rather than a hindrance.

The fundamental structure is the s-expression. It consists of an atom, or a list of s-expressions. This simply defined recursive structure allows complex structures to easily be specified. For example

3
(1 2 3)
(a (b c) d)
((a b) (d e))

Unlike other programming languages Scheme's data and code are in the same format, s-expressions. Thus s-expression are evaluated, recursively.

Symbols:

are treated as variables and evaluated return their currently set value.

Strings and numbers:

evalutate to themselves.

Lists:

The each member of the list is evaluated and the first item in the list is treated as a function and applied using the remainer of the list as arguments to the function.

Thus the s-expression

(+ 1 2)

when evaluated will return 3 as the symbol + is bound to a function that adds it arguments.

Variables may be set using the set! function which takes a variable name and a value as arguments

(set! a 3)

The set! function is unusual in that it does not evaluate its first argument. If it did you have to explcitly quote it or set some other variable to have a value of a to get the desired effect.

quoting, define