2.2.1 Scheme function definitions

The general form for defining scheme functions is:

function =
#(define-scheme-function
     (parser location arg1 arg2 …)
     (type1? type2? …)
   body)

where

argNnth argument
typeN?a scheme type predicate for which argN must return #t. Some of these predicates are specially recognized by the parser, see below.
bodyA sequence of scheme forms evaluated in order, the last one being used as the return value of the scheme function. It may contain LilyPond code blocks enclosed in hashed braces ( #{…#} ), like described in Lilypond code blocks. Within LilyPond code blocks, use $ to reference function arguments (eg., ‘$arg1’) or to start an inline scheme expression containing function arguments (eg., ‘$(cons arg1 arg2)’).

Some type predicates are specially recognized by the parser and will make the parser look for the respective arguments in Lilypond syntax rather than in Scheme syntax. Currently these are ly:music?, markup?, ly:pitch?, and ly:duration?.

If you really want to input one of the special items as a Scheme rather than a Lilypond expression, you may write them as a Scheme expression that calls ly:export at its outermost level.

Other type predicates, including user-defined ones, will make the respective argument only be accepted as a Scheme expression, usually introduced with # or as the result of calling a scheme function itself.

For a list of available type predicates, see Predefined type predicates.

See also

Notation Reference: Predefined type predicates.

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


LilyPond — Extending