LilyPond Notation Reference: 5.6.1 Substitution function syntax

### 5.6.1 Substitution function syntax

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

>     function =
>     #(define-music-function
>          (parser location arg1 arg2 …)
>          (type1? type2? …)
>        #{
>          …music…
>        #})

where

`argN` | nth argument
`typeN?` | a scheme type predicate for which `argN` must return `#t`.
`…music…` | normal LilyPond input, using `$` to reference arguments (eg. ‘`$arg1`’).

The `parser` and `location` arguments are mandatory, and are used in some advanced situations as described in the ‘Extending’ manual (see Music functions). For substitution functions, just be sure to include them.

The list of type predicates is also required. Some of the most common type predicates used in music functions are:

>     boolean?
>     cheap-list?  (use instead of ‘list?’ for faster processing)
>     ly:music?
>     markup?
>     number?
>     pair?
>     string?
>     symbol?

For a list of available type predicates, see Predefined type predicates. User-defined type predicates are also allowed.

#### See also

Notation Reference: Predefined type predicates.

Extending: Music functions.

Installed Files: ‘`lily/music-scheme.cc`’, ‘`scm/c++.scm`’, ‘`scm/lily.scm`’.

Andere talen: deutsch, español, 日本語.

#### LilyPond — Notation Reference