GNU LilyPond Notation Reference: 6.1.1 Overview of music functions

### 6.1.1 Overview of music functions

Making a function which substitutes a variable into LilyPond code is easy. The general form of these functions is

>     function =
>     #(define-music-function (parser location var1 var2...vari... )
>                             (var1-type? var2-type?...vari-type?...)
>       #{
>         ...music...
>       #})

where

vari | ith variable
vari-type? | type of ith variable
...music... | normal LilyPond input, using variables as `#$var1`, etc.

There following input types may be used as variables in a music function. This list is not exhaustive; see other documentation specifically about Scheme for more variable types.

Input type | vari-type? notation
--- | ---
Integer | `integer?`
Float (decimal number) | `number?`
Text string | `string?`
Markup | `markup?`
Music expression | `ly:music?`
A pair of variables | `pair?`

The `parser` and `location` arguments are mandatory, and are used in some advanced situations. The `parser` argument is used to gain access to the value of another LilyPond variable. The `location` argument is used to set the ‘origin’ of the music expression that is built by the music function, so that in case of a syntax error LilyPond can tell the user an appropriate place to look in the input file.

Other languages: español.

#### Notation Reference