On Wed, Dec 15, 2010 at 11:35:32AM -0700, Carl Sorensen wrote: > On 12/15/10 9:29 AM, "Juha Erkkila" <j...@turnipsi.no-ip.org> wrote: > > Is it possible to define functions that generate music functions > > in Lilypond? I'm looking something to this effect: > > > > ----- > > \version "2.12.3" > > > > musicA = #(define-music-function (parser location music) > > (ly:music?) > > #{ c4 d e f $music #}) > > > > \musicA { g4 a b a } > > > > % makeMusicFn = #(define-music-function (parser location prepend-music) > > % (ly:music?) > > % (define-music-function (parser location append-music) > > % (ly:music?) > > % #{ $prepend-music $append-music #})) > > % > > % musicB = \makeMusicFn { c4 d e f } > > % > > % \musicB { g4 a b a } > > ----- > > > > Here expressions "\musicA { g4 a b a }" and "\musicB { g4 a b a }" > > should evaluate to same music expression, that is > > { c4 d e f g4 a b a }. The expressions that are commented out are > > attempts to achieve what I'm looking for. The above syntax is, > > however, wrong, as define-music-function must return a music > > expression, not a function. > > Music functions must return music expressions, but scheme functions can > return functions. > > Are you after this specific behavior, or some other behavior, of which this > is a simplified example?
The above was just a simplified example, the actual case I try to do is more complex. Anyway, this solution is enough for me: ----- \version "2.12.3" musicA = #(define-music-function (parser location music) (ly:music?) #{ c4 d e f $music #}) \musicA { g4 a b a } #(define (musicFn prepend-music) (ly:make-music-function (list ly:music?) (lambda (parser location append-music) #{ $prepend-music $append-music #}))) musicB = #(musicFn #{ c4 d e f #}) \musicB { g4 a b a } ----- Thanks for the tips. It's good to see scheme and lilypond play together so nicely! Juha _______________________________________________ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user