Sunday, December 14, 2008

Basic Scheme in LilyPond input files

Perhaps the simplest LilyPond file looks like this.

\new Staff { c'4 }

The LilyPond input file looks like its own language with backslash-prefixed commands similar to LaTeX. But LilyPond input is in fact Scheme. Pure Scheme commands prefixed with # mix freely in LilyPond input. The following examples mix LilyPond and pure Scheme together.

Example 1.

#(print "hello!")
\new Staff { c'4 }


Example 2.

#(define foo "FOO")
#(print foo)
\new Staff { c'4 }


Example 3.

#(define bar 7)
#(print (number->string bar))
\new Staff { c'4 }


Other examples are possible. Best of all will be functions to print out LilyPond context names or grob settings during interpretation.