This section lists the basic functions in Festival's Scheme. It doesn't list them all (see the Festival manual for that) but does highlight the key functions that you should normally use.
These functions are the basic functions used in Scheme. These include the structural functions for setting variables, conditionals. loops, etc.
(set! SYMBOL VALUE)
(set! a 3)
(set! pi 3.14)
(set! fruit '(apples pears bananas))
(set! fruit2 fruit)
(define (FUNCNAME ARG0 ARG1 ...) . BODY)
(define (myadd a b) (+ a b))
(define (factorial a)
((< a 2) 1)
(t (* a (factorial (- a 1))))))
(if TEST TRUECASE [FALSECASE] )
(if (string-equal v "apples")
(format t "It's an apple\n")
(format t "It's not an apple\n"))
(if (member v '(apples pears bananas))
(format t "It's a fruit (%s)\n" v)
(cond (TEST0 . BODY) (TEST1 . BODY) ...)
((string-equal v "apple")
((string-equal v "plum")
((string-equal v "peach")
(begin . BODY )
This evaluates each s-expression in
BODY and returns the value
of the last s-expression in the list. This is useful for case
where only one s-expression is expected but you need to call a number
of functions, notably the
(if (string-equal v "pear")
(format t "assuming it's a asian pear\n")
(or . DISJ)
(or (string-equal v "tortoise")
(string-equal v "turtle"))
(or (string-equal v "pear")
(string-equal v "apple")
(< num_fruits 6))
(and . CONJ)
(and (< num_fruits 10)
(> num_fruits 3))
(and (string-equal v "pear")
(< num_fruits 6)
(or (string-equal day "Tuesday")
(string-equal day "Wednesday")))
(car '(a b)) => a
(car '((a b) c d)) => (a b)
(car '(a (b c) d)) => a
(car nil) => nil
(car 'a) => nil
(cdr '(a b)) => (b)
(cdr '((a b) c d)) => (c d)
(cdr '(a)) => nil
(cdr '(a (b c))) => ((b c))
(cdr nil) => nil
(cdr 'a) => nil
(cons EXPR0 EXPR2)
(cons 'a '(b c)) => (a b c)
(cons 'a ()) => (a)
(cons '(a b) '(c d) => '((a b) c d))
(cons () '(a) => '(nil a))
(cons 'a 'b => (a . b))
(cons nil nil) => (nil)
(list . BODY)
(list 'a 'b 'c) => (a b c)
(list '(a b) 'c 'd) => ((a b) c d)
(list nil '(a b) '(a b)) => (nil (a b) (a b))
(append . BODY)
(append '(a b) '(c d)) => (a b c d)
(append '(a b) '((c d)) '(e f)) => (a b (c d) e f)
(append nil nil) => nil
(append '(a b)) => (a b))
(append 'a 'b) => error
(nth N LIST)
(nth 0 '(a b c)) => a
(nth 2 '(a b c)) => c
(nth 3 '(a b c)) => nil
(nth_cdr N LIST)
(nth 0 '(a b c)) => (a b c)
(nth 2 '(a b c)) => (c)
(nth 1 '(a b c)) => (b c)
(nth 3 '(a b c)) => nil
(last '(a b c)) => (c)
(last '(a b (c d))) => ((c d))
(reverse '(a b c)) => (c b a)
(reverse '(a)) => (a)
(reverse '(a b (c d))) => ((c d) b a)
(member ITEM LIST)
(member 'b '(a b c)) => (b c)
(member 'c '(a b c)) => (c)
(member 'd '(a b c)) => nil
(member 'b '(a b c b)) => (b c b)
eqto test equality, hence this does not work for strings. You should use
member_stringif the list contains strings.
(assoc ITEM ALIST)
a-list are a standard list format for representing feature value pairs. An a-list is basically a list of pairs of name and value, although the name may be any lisp item it is usually an symbol. A typlical a-list is
(occurs ("file01" "file04" "file07" "file24"))
associs a function that allows you to look up values in an a-list
(assoc 'name '((name AH) (duration 0.95))) => (name AH)
(assoc 'duration '((name AH) (duration 0.95))) => (duration 0.95)
(assoc 'vowel '((name AH) (duration 0.95))) => nil
eqto test equality, hence this does not work names that are strings. You should use
assoc_stringif the a-list uses strings for names.
+ - * / exp log sqrt < > <= >= =
File names in Festival use the Unix convention of using "/" as the directory separator. However under other operating systems, such as Windows, the "/" will be appropriately mapped into backslash as required. For most cases you do not need to worry about this and if you use forward slash all the time ti will work.
(format FD FORMATSTRING . ARGS)
format function is a little unusually in
Lisp. It basically follows the
printf command in C,
or more closely follows the
format function in
Emacs lisp. It is desgined to print out infomation that is not
necessarily to be read in by Lisp (unlike
FD is a file
descriptor as created by
fopen, and the result is
printed to that. Also two special values are allows
t causes the output to be sent to standard
out (which is usually the terminal).
the output to be written to a string and returned by the
function. Also the variable
stderr is set to a file
descriptor for standard error output.
The format string closely follows the format used in C's printf
functions. It is actually interpreted by those functions in its
format supports the following directives
Print as integer
Print as integer in hexadecimal
Print as float
Convert item to string
A percent character
Print as double
Print number as character
Print as Lisp object
%*sare not supported, nor is
%s directive will try to convert the corresponding
lisp argument to a string before passing it to the low level print
function. Thus list will be printed to strings, and numbers also
coverted. This form will loose the distinction between lisp symbols
and lisp strings as the quote will not be present in the
form. In general
%s should be used for getting nice human
output and not for machine readable output as it is a lossy print
(format t "duration %0.3f\n" 0.12345) => duration 0.123
(format t "num %d\n" 23) => num 23
(format t "num %04d\n" 23) => num 0023
Pretty print give expression to standard out (or FD if specified). Pretty printing is a technique that inserts newlines in the printout and indentation to make the lisp expression easier to read.
This creates a file description, which can be used in the various I/O
functions. It closely follows C stdio
fopen function. The
mode may be
to open the file for reading
to open the file for writing
to open the file at the end for writing (so-called, append).
File I/O in binary (for OS's that make the distinction),
Close a file descriptor as created by
Read next s-expression from standard in
(let ((ifd (fopen infile "r"))
(ofd (fopen outfile "w"))
(while (not (equal? (set! word (readfp ifd)) (eof-val)))
(format ofd "%l\n" (lex.lookup word nil)))
Load in the s-expressions in
unspecified the s-expressions are evaluated as they are read. If
NOEVAL is specified and non-nil,
load will return all
s-expressions in the file un-evaluated in a single list.
As in many other languages, Scheme has a distinction between
symbols. String evaluate to themselves and
cannot be assigned other values, symbols of the print name are
equal? while strings of teh same name aren't necessarily.
In Festival's Scheme, strings are eight bit clean and designed to hold strings of text and characters in what ever language is being synthesized. Strings are always treats as string of 8 bit characters even though some language may interpret these are 16-bit characters. Symbols, in general, should not contain 8bit characters.
(string-equal STR1 STR2)
Finds the string of
STR2 and returns
these are equal, and
nil otherwise. Symbol names and numbers are
mapped to string, though you should be aware that the mapping of a
number to a string may not always produce what you hope for. A number
0 may or may not be mapped to
"0" or maybe to
such that you should not dependent on the mapping. You can use
format to map a number ot a string in an explicit manner. It is
however safe to pass symbol names to
string-equal. In most cases
string-equal is the right function to use rather than
equal? which is must stricter about its definition of equality.
(string-equal "hello" "hello") => t
(string-equal "hello" "Hello") => false
(string-equal "hello" 'hello) => t
(string-append . ARGS)
(string-append "abc" "def") => "abcdef"
(string-append "/usr/local/" "bin/" "festival") => "/usr/local/bin/festival"
(string-append "/usr/local/" t 'hello) => "/usr/local/thello"
(string-append "abc") => "abc"
(string-append ) => ""
(member_string STR LIST)
nil if no member of
STR, otherwise it returns
t. Again, this is often the
safe way to check membership of a list as this will work properly if
STR or the members of
LIST are symbols or strings.
(member_string "a" '("b" "a" "c")) => t
(member_string "d" '("b" "a" "c")) => nil
(member_string "d" '(a b c d)) => t
(member_string 'a '("b" "a" "c")) => t
(string-before STR SUBSTR)
(string-before "abcd" "c") => "ab"
(string-before "bin/make_labs" "/") => "bin"
(string-before "usr/local/bin/make_labs" "/") => "usr"
(string-before "make_labs" "/") => ""
(string-after STR SUBSTR)
(string-after "abcd" "c") => "d"
(string-after "bin/make_labs" "/") => "make_labs"
(string-after "usr/bin/make_labs" "/") => "bin/make_labs"
(string-after "make_labs" "/") => ""
(length "") => 0
(length "abc") => 3
(length 'abc) -> SIOD ERROR
(length '(a b c)) -> 3
(symbolexplode 'abc) => ("a" "b" "c")
(symbolexplode 'hello) => ("h" "e" "l" "l" "o")
Convert a string into a symbol with the same print name.
(string-matches STR REGEX)
(string-matches "abc" "a.*") => t
(string-matches "hello" "[Hh]ello") => t
In order to interact more easily with the underlying operating system, Festival Scheme includes a number of basic function that allow Scheme programs to make use of the operating system functions.
(system "ls") => lists files in current directory.
(system (format nil "cat %s" filename))
(get_url URL OFILE)
(get_url "http://www.festvox.org/index.html" "festvox.html")
(setenv NAME VALUE)
(setenv "DISPLAY" "nara.mt.cs.cmu.edu:0.0")
(set! bbbfile (format nil "/tmp/stuff.%05d" (getpid)))
return a string which is a pathname to the current working directory.
%%%%% Utterance construction and access functions
%%%%% Synthesis specific functions