1.1.2 Scheme variables

Scheme variables can have any valid Scheme value, including a Scheme procedure.

Scheme variables are created with define:

guile> (define a 2)
guile>

Scheme variables can be evaluated at the guile prompt simply by typing the variable name:

guile> a
$1 = 2
guile>

The dollar sign followed by a number is a reference to the result of the just evaluated expression (the variable ‘a’), which you can find on the right side of the equal sign; it can be used later on for evaluation:

guile> (+ $1 $1)
$2 = 4
guile>

If a Scheme expression evaluates to nothing (as does the call to define above), no such reference is shown. Don’t be worried if the number after the dollar sign shown in this tutorial differs from what you get while playing around with the sandbox.

Scheme variables can be printed on the display by using the display function:

guile> (display a)
2guile>

Note that both the value 2 and the guile prompt guile showed up on the same line. This can be avoided by calling the newline procedure or displaying a newline character.

guile> (display a)(newline)
2
guile> (display a)(display "\n")
2
guile>

Once a variable has been created, its value can be changed with set!:

guile> (set! a 12345)
guile> a
$3 = 12345
guile>

Extending LilyPond v2.27.0 (development-branch).